我正在使用 Quartz 在 iOS 上创建透明图像。但是,此图像在模拟器中以适当的透明度显示,但在设备上显示为白色背景。
这是我为此使用的代码:
+ (UIImage *)clearRect:(CGRect)rect inImage:(UIImage *)image {
if (UIGraphicsBeginImageContextWithOptions != NULL)
UIGraphicsBeginImageContextWithOptions([image size], NO, 0.0);
else
UIGraphicsBeginImageContext([image size]);
CGContextRef context = UIGraphicsGetCurrentContext();
[image drawInRect:CGRectMake(0.0, 0.0, [image size].width, [image size].height)];
CGContextClearRect(context, rect);
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
NSData *data= UIImagePNGRepresentation(result);
UIImage *img = [UIImage imageWithData:data];
UIGraphicsEndImageContext();
return img;
}
这是我在设备上看到的:
我可能做错了什么?