2
A
回答
1
我找到了一個解決方案:
- (UIImage*)convertToInverseWhiteMask: (UIImage *) image {
UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
CGRect imageRect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// Draw a white background (for white mask)
CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f);
CGContextFillRect(ctx, imageRect);
// Apply the source image's alpha
[image drawInRect:imageRect blendMode:kCGBlendModeDestinationOut alpha:1.0f];
UIImage* mask = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return mask;
}
0
這裏是我使用的是什麼:
- (UIImage *)imageWithTintedColor:(UIImage *)image withTint:(UIColor *)color withIntensity:(float)alpha
{
CGSize size = image.size;
UIGraphicsBeginImageContextWithOptions(size, FALSE, [[UIScreen mainScreen] scale]);
CGContextRef context = UIGraphicsGetCurrentContext();
[image drawAtPoint:CGPointZero blendMode:kCGBlendModeNormal alpha:1.0];
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextSetBlendMode(context, kCGBlendModeSourceAtop);
CGContextSetAlpha(context, alpha);
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(CGPointZero.x, CGPointZero.y, image.size.width, image.size.height));
UIImage * tintedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return tintedImage;
}
相關問題
- 1. 透明像素顏色 - 去朗圖像
- 2. UItextview透明顏色IOS
- 3. CSS對父顏色透明
- 4. iOS着色透明圖像
- 5. OpenCV Floodfill - 用透明像素替換像素顏色
- 6. 使黑色像素透明
- 7. UIPageViewController和UIPageControl透明背景顏色 - iOS
- 8. iOS顏色在UIImage中透明
- 9. 透明背景顏色,但只有透明
- 10. 透明圖像頂部顏色
- 11. 透明圖像 - 背景顏色
- 12. 核心圖像 - 顏色切換透明
- 13. 使用透明顏色旋轉圖像
- 14. css透明圖像的背景顏色
- 15. 改變透明圖像顏色動態
- 16. 透明png不顯示bg圖像只是bg顏色在html
- 17. ImageMagick - 通過顏色透明圖像透明
- 18. 如何在iOS中更改部分透明圖像的顏色?
- 19. java獲得像素的顏色透明,漸變疊加
- 20. Imagemagick將不透明像素轉換爲特定顏色
- 21. 使所有顏色的像素不透明
- 22. XNA:僅將SpriteBatch.Draw(...)顏色應用於不透明像素
- 23. Vb.net變化像素顏色設爲透明
- 24. BitmapFactory.decodeByteArray在像素完全透明時不保留顏色信息
- 25. php imagick畫一個顏色的所有非透明像素
- 26. 更改java中透明像素的顏色
- 27. XNA Texture2D.FromStream不保存完全透明像素中的顏色
- 28. 混合透明顏色
- 29. Html rgba顏色不透明?
- 30. Java - 不透明顏色
所以它張貼作爲一個答案:) –