iOS圆型截图发现白色背景问题:
费了很多时间才发现,是非PNG格式,无法保存:
UIGraphicsBeginImageContextWithOptions(asize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 1);
CGContextSetStrokeColorWithColor(context, [UIColor clearColor].CGColor);
CGRect rect = CGRectMake(0, 0,asize.width, asize.height);
CGContextAddEllipseInRect(context, rect);
CGContextClip(context);
[image drawInRect:rect];
CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context);
newimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
同时注意转化一下:
/* PNG才能直接用截图上 */
NSData *pngData = UIImagePNGRepresentation(image);
UIImage *pngImage = [UIImage imageWithData:pngData];
UIImage *scaleImage = [UIImage thumbnailWithImageWithoutScale:pngImage size:CGSizeMake(fixelW, fixelH)];
[UIImagePNGRepresentation(scaleImage) writeToFile:imageFilePath atomically:YES];