【问题标题】:RGBStroke - Image pixels instead of color (iOS)RGBStroke - 图像像素而不是颜色 (iOS)
【发布时间】:2013-10-07 06:35:56
【问题描述】:

我正在 iOS 中实现一种图像蒙版功能,类似于 Blender 应用程序中提供的带有两个图像的功能。这是我的触摸移动代码:-

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

    UITouch *touch = [touches anyObject];
    CGPoint currentPoint = [touch locationInView:staticBG1];

    UIGraphicsBeginImageContext(view.frame.size);
    [image_1 drawInRect:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];

    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 20.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());

    image_1 = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;
    mouseMoved++;
    if (mouseMoved == 10)
        mouseMoved = 0;
}

现在我真正想要的是不是明亮的红线,而是来自其他图像的像素。两个图像具有相同的尺寸。我该怎么做?? 我试图实现我的手动图像处理方法我的像素访问,但它太慢了,这将实时完成。

是否有任何替代方案: CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); ?

【问题讨论】:

    标签: objective-c core-graphics image-masking


    【解决方案1】:

    不要在路径中绘制颜色或图案,绘制透明度。您需要在要删除的图像后面的自己的图层中放置一个图像。按照现在的方式创建路径,但不要设置颜色,而是将混合模式设置为清除 (kCGBlendModeClear)。

    这将删除图像的某些部分,以便您看到下面的图像。


    替换:

    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
    

    与:

    CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear); 
    

    【讨论】:

    • 您能否详细说明一下。我用 CGContextDrawImage(UIGraphicsGetCurrentContext(), rect, [staticBG2.image CGImage]);而不是 RGB 颜色值,但这会在基础图像中多次绘制另一个图像。
    • 清除模式应该在绘制图像之后和描边之前设置。这个想法是将路径清除为透明,因此您可以删除先前绘制到上下文中的图像(而不是在顶部添加颜色)。
    • 我在路径中多次绘制整个背面图像,然后将其混合......我的错。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-10
    • 2018-05-06
    • 2011-06-04
    • 2021-05-16
    • 2011-09-22
    相关资源
    最近更新 更多