我一直以來有代碼在我的iPhone應用程序的一個片段,試圖掩蓋一些JPEG圖像的白色背景。今天,這條消息在iPhone上仍然運行良好,但並不掩蓋Apple Watch。該代碼在預期成功(非NULL
)路徑上運行,但不執行屏蔽。即使我的maskingColors
陣列改變爲範圍0.0, 255.0
每個組件,沒有掩蔽,進行當在WKInterfaceImage
顯示(具有setImage:
)(在iPhone上完全掩蓋圖像此相同的變化)。CGImageCreateWithMaskingColors不能在Apple關注面具WKInterfaceImage
與存儲在資產目錄alpha通道PNG圖像似乎在WKInterfaceImage
到蘋果觀看正常顯示。
是CGImageCreateWithMaskingColors
不是Apple關注安全嗎?
- (UIImage *)imageWithBackgroundRemovedWithImageData:(NSData *)imageData
{
CGImageRef originalImage = [UIImage imageWithData:imageData].CGImage;
/* Only attempt for RGB images */
if (CGColorSpaceGetModel(CGImageGetColorSpace(originalImage)) != kCGColorSpaceModelRGB)
return ([UIImage imageWithData:imageData]);
/* Mask 10 shades of "white" */
static const CGFloat maskingColors[] = {245.0, 255.0, 245.0, 255.0, 245.0, 255.0};
CGImageRef transparentImageRef = CGImageCreateWithMaskingColors(originalImage, maskingColors);
if (transparentImageRef == NULL)
return ([UIImage imageWithData:imageData]);
UIImage *transparentImage = [UIImage imageWithCGImage:transparentImageRef];
CGImageRelease(transparentImageRef);
return (transparentImage);
}
您可以添加Watch代碼(即如何編碼和設置圖像)? –
@MikeSwanson我簡單地在'WKInterfaceTable'的一行中用'WKInterfaceImage'返回發佈的代碼來調用'setData'。我發送的'NSData'從iPhone應用程序以JPEG形式從網站下載,並從'openParentApplication'的'reply'塊傳輸到手錶。我也嘗試在手機上執行屏蔽步驟,並將產生的'UIImagePNGRepresentation()'發送到手錶,結果相同。 – greg
更正:setImage,顯然不是setData。 – greg