Question

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);

    ...?   

}
Était-ce utile?

La solution

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;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top