0
我正在使用一點變通方法來成功保存帶有蒙版的圖像(因爲您無法使用CoreAction渲染蒙版)。如何在CGContext上分層
這裏是我的代碼:
CGContextRef context = CGBitmapContextCreate(nil, cWidth, cHeight, bitsPerComponent, bytesPerRow, CGColorSpaceCreateDeviceRGB(), CGImageGetBitmapInfo(image));
//the mask:
CGContextClipToMask(context, CGRectMake(0,0,1280,935), self.image.image.CGImage);
//the image to mask:
CGContextDrawImage(context, CGRectMake(0, 0, 1280,935), viewImage.CGImage);
CGImageRef mergeResult = CGBitmapContextCreateImage(context);
saver = [[UIImage alloc] initWithCGImage:mergeResult];
所以這個工作得很好,面具削減了一切的形狀外的目標形象。這使得周圍的區域和背景變成白色。我不想顯示白色,我想顯示一個圖像/顏色/圖案等,所以我基本上喜歡在所有背後堆疊另一個圖像。
這怎麼辦?謝謝
嗨,我其實試過這個,但無濟於事。看起來發生的是第一個CGContextDrawImage接管整個事情。 – user339946 2012-03-08 19:01:04
其實,從頭開始。這是我的錯誤。一種幻覺讓我誤以爲我的面具沒有出現。謝謝 – user339946 2012-03-08 19:10:41