RGBStroke-图像像素而不是颜色(iOS) [英] RGBStroke - Image pixels instead of color (iOS)

查看:108
本文介绍了RGBStroke-图像像素而不是颜色(iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am implementing a image mask kind of feature in iOS similar to what is offered in the Blender app with two images. Here is my touch move code :-

- (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;
}

现在我真正想要的是不是亮红色的线条而是像素从那些地方的另一张图片中。两个图像的尺寸相同。我该怎么做??
我尝试用像素访问来实现手动图像处理方法,但是它太慢了,无法实时完成。

Now what I really want is not the bright red line but pixels from another image in those places. Both images are of the same dimensions. How do I do it?? I tried to implement my manual image processing method my pixel access but it was too slow and this will be done in real time.

有什么替代方法吗? :
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),1.0,0.0,0.0,1.0);

Is there any alternative to: CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); ?

推荐答案

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

Don't draw a colour or a pattern into the path, draw transparency. You need one image in its own layer behind the image that is being wiped out. Create the path as you are now, but instead of setting the colour, set the blend mode to clear (kCGBlendModeClear).

这将删除图像的各个部分,以使您可以浏览下面的图像。

This will remove sections of the image to allow you to see through to the image below.

替换:

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

具有:

CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear); 

这篇关于RGBStroke-图像像素而不是颜色(iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆