[英]Why is this transparent image showing up with a white background on a device?
我正在使用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;
}
這是我在設備上看到的內容:
我可能做錯了什么?
鑒於代碼可以在模擬器中運行,而不是在您的設備中運行,因此您可能成為了下面描述的Cruftmonster的受害者:
http://weblog.bignerdranch.com/642-beware-the-cruftmonster/
您可能有一些舊文件已從Xcode項目中刪除,但尚未從設備上的應用程序捆綁中刪除。 您最初是否使用不透明圖像進行測試?
不知道這是否是解決方案,但它肯定與您描述的症狀相符。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.