【问题标题】:Category on UIImage to return a blank UIImage?UIImage 上的类别返回空白 UIImage?
【发布时间】:2014-02-24 21:13:38
【问题描述】:
如何从上下文创建 UIImage 以便可以返回它?我只希望它具有透明像素。我有一种不同的方法,可以将较小的 UIImage 添加到较大的 UIImage 中,但我需要一个空白的开始。
+ (UIImage *)blankUIImageOfSize:(CGSize)size {
UIGraphicsBeginImageContextWithOptions(size, NO, 1);
...?
}
【问题讨论】:
标签:
ios
objective-c
uiimage
quartz-graphics
【解决方案1】:
以下应该有效:
+ (UIImage *)blankUIImageOfSize:(CGSize)size {
UIGraphicsBeginImageContextWithOptions(size, NO, 1);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, CGRectMake(0, 0, area.width, area.height));
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}