How do I create a UIImage from a context so that I can return it? I just want it to have transparent pixels. I have a different method that adds smaller UIImages to a larger one, but I need a blank slate to begin with.

+ (UIImage *)blankUIImageOfSize:(CGSize)size {
    UIGraphicsBeginImageContextWithOptions(size, NO, 1);

    ...?   

}
有帮助吗?

解决方案

The following should work:

+ (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;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top