小编max*_*der的帖子

iOS CoreGraphics:用半透明图案抚摸会导致颜色损坏

我的任务是制作一个类似于擦除工具(用手指操作)的东西,它将显示背景图像而不是擦除图像.

这是我的源图像和目标图像(仅用于测试,实际图像将有所不同):

此搜索 http://img232.imageshack.us/img232/6030/29572847.png

这是我的代码.创建模式:

- (void)setFrame:(CGRect)frame {
   [super setFrame:frame];
   if(revealPattern) CGPatternRelease(revealPattern);
   CGPatternCallbacks callbacks = { 0, &patternCallback, NULL};
   revealPattern = CGPatternCreate(self, self.bounds, CGAffineTransformIdentity, self.bounds.size.width, self.bounds.size.height, kCGPatternTilingConstantSpacing, true, &callbacks);   
}
Run Code Online (Sandbox Code Playgroud)

模式回调函数(**info*包含指向self的指针):

void patternCallback(void *info, CGContextRef context) {
   CGRect rect = ((DrawView *)info).bounds;
   CGImageRef imageRef = ((DrawView *)info).backgroundImage.CGImage;
   CGContextTranslateCTM(context, 0, rect.size.height);
   CGContextScaleCTM(context, 1.0, -1.0);
   CGContextDrawImage(context, rect, imageRef);
}
Run Code Online (Sandbox Code Playgroud)

和绘图方法:

- (void)drawPoints:(CGContextRef)context{
   if([points count] < 2) return;
   CGPoint lastPoint = [[points objectAtIndex: 0] CGPointValue];
   CGContextBeginPath(context);
   CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);

   CGContextSetBlendMode(context, kCGBlendModeNormal);
   CGColorSpaceRef …
Run Code Online (Sandbox Code Playgroud)

iphone core-graphics ios

8
推荐指数
1
解决办法
992
查看次数

标签 统计

core-graphics ×1

ios ×1

iphone ×1