0
在iOS應用程序中。我想拖放圖像到我放置PNG圖像的UIImageView上。我只是想要這些顏色在圖像內,但不是在透明區域。附件圖片可以說明我的問題更多的好在png圖像上拖放顏色
我想從底部拖動圖像,並在下降,它應該是這樣的。
在底部,這些顏色可以被認爲是UIImageViews的
在iOS應用程序中。我想拖放圖像到我放置PNG圖像的UIImageView上。我只是想要這些顏色在圖像內,但不是在透明區域。附件圖片可以說明我的問題更多的好在png圖像上拖放顏色
我想從底部拖動圖像,並在下降,它應該是這樣的。
在底部,這些顏色可以被認爲是UIImageViews的
- (UIImage *) changeColorForImage:(UIImage *)image toColor:(UIColor*)color {
UIGraphicsBeginImageContext(image.size);
CGRect contextRect;
contextRect.origin.x = 0.0f;
contextRect.origin.y = 0.0f;
contextRect.size = [image size];
// Retrieve source image and begin image context
CGSize itemImageSize = [image size];
CGPoint itemImagePosition;
itemImagePosition.x = ceilf((contextRect.size.width - itemImageSize.width)/2);
itemImagePosition.y = ceilf((contextRect.size.height - itemImageSize.height));
UIGraphicsBeginImageContext(contextRect.size);
CGContextRef c = UIGraphicsGetCurrentContext();
// Setup shadow
// Setup transparency layer and clip to mask
CGContextBeginTransparencyLayer(c, NULL);
CGContextScaleCTM(c, 1.0, -1.0);
CGContextClipToMask(c, CGRectMake(itemImagePosition.x, -itemImagePosition.y, itemImageSize.width, -itemImageSize.height), [image CGImage]);
// Fill and end the transparency layer
CGContextSetBlendMode(c, kCGBlendModeColorDodge);
CGContextSetFillColorWithColor(c, color.CGColor);
contextRect.size.height = - contextRect.size.height;
contextRect.size.height -= 15;
CGContextFillRect(c, contextRect);
CGContextEndTransparencyLayer(c);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
我相信它會幫助你。
這真的很不錯。它改變了圖像的整個顏色。但想要在特定區域添加顏色,如附圖 – Mashhadi
中所述,應該使用核心圖形繪製這些區域(4),但無法幫助您繪製上下文。並分別改變顏色 –