/*
* str 添加的文字
* image 背景图
* position 添加的位置
*/
- ( UIImage *)createShareImage:( NSString *)str andImage:(UIImage *)image andPosiTion:(CGPoint )position
{
CGSize size= CGSizeMake ( image.size.width , image.size.height); // 画布大小
UIGraphicsBeginImageContextWithOptions (size, NO , 0 );
[image drawAtPoint : CGPointMake ( 0 , 0 )];
// 获得一个位图图形上下文
CGContextRef context= UIGraphicsGetCurrentContext ();
CGContextDrawPath (context, kCGPathStroke );
// 画
NSMutableAttributedString * mutable=[[NSMutableAttributedString alloc] initWithString:str];
NSTextAttachment *attachment1=[[NSTextAttachment alloc] init];
attachment1.image=[UIImage imageNamed:@"icon_beizhu"];
attachment1.bounds=CGRectMake(0, -5, 20, 20);
NSAttributedString * attachStr1 = [NSAttributedString attributedStringWithAttachment:attachment1];
[mutable insertAttributedString:attachStr1 atIndex:0];
[mutable addAttribute:NSForegroundColorAttributeName value:ryellow range:NSMakeRange(1, str.length)];
[mutable addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(1, str.length)];
//图片的压缩比例
CGFloat imageY=13+64+98/2+15;
CGFloat widthScale = image.size.width/(ScreenWidth-36);
CGFloat heightScale = image.size.height/(ScreenHeight-imageY-76/2-61);
CGFloat rectX=position.x*widthScale;
CGFloat rectY=position.y*heightScale;
[mutable drawWithRect:CGRectMake(rectX, rectY, 200, 200) options:NSStringDrawingUsesLineFragmentOrigin context:nil];
// [str drawAtPoint : CGPointMake ( 30 , image. size . height * 0.65 ) withAttributes : @{ NSFontAttributeName :[ UIFont fontWithName : @"Arial-BoldMT" size : 30 ], NSForegroundColorAttributeName :[ UIColor whiteColor ] } ];
// 返回绘制的新图形
UIImage *newImage= UIGraphicsGetImageFromCurrentImageContext ();
UIGraphicsEndImageContext ();
return newImage;
}