我需要一個UIImageView,可以自行繪製的顏色或b /根據標誌寬:如何繪製形狀上一個UIImage的頂部,同時尊重圖像的alpha掩蓋
BOOL isGrey;
我想通過在Quartz blendmode設置爲Color的原始圖像頂部繪製黑色矩形來實現。這個工作除了不尊重圖像的alpha蒙版。
見圖示: alt text http://img214.imageshack.us/img214/1407/converttogreyscaleillo.png
搜索谷歌和SO,我發現並試圖幾種解決方案,但沒有任何尊重的面具。
這裏是產生上述的「我所得到的」形象代碼:
- (void)drawRect:(CGRect)rect {
if (isGrey) {
CGContextRef context = UIGraphicsGetCurrentContext();
// flip orientation
CGContextTranslateCTM(context, 0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
// draw the image
CGContextDrawImage(context, self.bounds, self.image.CGImage);
// set the blend mode and draw rectangle on top of image
CGContextSetBlendMode(context, kCGBlendModeSaturation);
CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextFillRect(context, rect);
} else {
[self.image drawInRect:rect];
}
}
有沒有辦法,我忘記設置一些石英繪圖模式?我已經看過Quartz編程指南,但很難從重疊和超鏈接主題中提取您需要的信息。
很顯然,我希望能夠找到適用於圖像與任何蒙面形狀,不只是顯示的圓一個通用的解決方案。
除了這不工作,如果你的觀點backgroundColor是UIColor clearColor。 – 2011-06-10 21:20:45