1
我試圖用iOS中的觸摸擦除圖像。通過設置混合模式爲kCGBlendModeClear,我可以做到這一點 - 但只有硬邊緣。我可以使用不同的線寬和alpha來繪製筆畫,但似乎CGContextSetAlpha對kCGBlendModeClear沒有影響。如何在CGBitmapContext中實現柔軟的橡皮擦筆觸
我該如何解決這個問題?透明層,前/後
CGPathRef pathToErase = ...; // The path you want erased
// could also be an image or (nearly) anything else
// that can be drawn in a bitmap context
CGContextSetBlendMode(ctx, kCGBlendModeDestinationOut);
CGContextBeginTransparencyLayer(ctx, NULL);
{
CGContextSetGrayFillColor(ctx, 0.0, 1.0); // solid black
CGContextAddPath(ctx, pathToErase);
CGContextFillPath(ctx);
// the above two lines could instead be CGContextDrawImage()
// or whatever else you're using to clear
}
CGContextEndTransparencyLayer(ctx);
請注意,您還應該保存和恢復gstate(CGContextSaveGState()
/CGContextRestoreGState()
):
謝謝,這工作得很好 - 我正在編輯kCGBlendModeDestinationOut – user441669