문제

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