简体   繁体   中英

PNG with transparent background shows black on older iPads

I have a bug in my iPad app that is driving me crazy. The app allows users to drop clipart onto pages. The clipart images are PNG with transparent backgrounds. I create a simple UIImageView and set opaque to NO. In all my testing, everything works perfectly. However, it seems that people with older iPads (maybe iPad 2?) these images have black backgrounds. It doesn't appear to be an issue with the iOS, but it appears to be an issue with the iPad.

Website where you can see 90-95% of the clipart images are perfectly fine, while 5-10% have the black backgrounds: http://www.printpad.com

Code I am using for the UIImageView:

UIImageView *imageView = [[UIImageView alloc] initWithImage:resized imageBorderColor:borderColor imageBorderWidth:borderWidth];
[imageView.layer setOpaque:NO];
imageView.opaque = NO;
imageView.frame = rect;
[view addSubview:imageView];

I really hope someone out there has encountered this and can help, as I can't even think of how to debug or anything. Thanks!!!!!

EDIT: The original image is downloaded into the Documents directory, and then it is resized like this:

UIImage *image = [UIImage imageWithContentsOfFile:path];
CGSize newSize = [MyUtility getNewSize:image.size maximumSize:CGSizeMake(200, 200)];
UIImage *resized = [UIImage imageWithImage:image scaledToSize:newSize];

Here is the imageWithImage category:

+ (UIImage *)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
    [self beginImageContextWithSize:newSize];
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    [self endImageContext];
    return newImage;
}

As with the answer here: https://stackoverflow.com/a/23355129/1751266

Is it possible that you're creating the image as opaque instead of transparent? If you're using UIGraphicsBeginImageContextWithOptions or similar then the second parameter should be NO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM