-
(UIImage *)cropImageWithValue:(CGFloat)value {
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, value);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();// 加字
[image drawAtPoint : CGPointMake ( 0 , 0 )];// 获得一个位图图形上下文
CGContextRef imageContext= UIGraphicsGetCurrentContext();CGContextDrawPath (imageContext, kCGPathStroke );
NSString str;
if (self.isGroup) {
str = @"长按识别/扫描二维码 加入群聊";
}else {
str = @"长按识别/扫描二维码 加我为好友";
}
CGSize textSize = [str boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
[str drawAtPoint : CGPointMake((self.view.width-textSize.width)0.5, image.size.height-25) withAttributes : @{ NSFontAttributeName:[UIFont systemFontOfSize:15], NSForegroundColorAttributeName:[UIColor blackColor]}];// 返回绘制的新图形
UIImage *textImage= UIGraphicsGetImageFromCurrentImageContext ();
UIGraphicsEndImageContext ();return textImage;
}
网友评论