[英]How to layer on the CGContext
我使用一些解決方法來成功保存帶有蒙版的圖像(因為無法使用CoreAction渲染蒙版)。
這是我的代碼:
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];
因此,此方法效果很好,遮罩會在目標圖像中切出其形狀以外的所有內容。 這會使周圍區域和背景變白。 我不想顯示白色,而是要顯示圖像/顏色/圖案等。因此,我基本上想在所有圖像之后堆疊另一個圖像。
如何才能做到這一點? 謝謝
首先將背景繪制到上下文中,然后進行裁剪,然后將圖像繪制到相同的上下文中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.