如何使用Image Magick库或iphone上的obj-c代码复制Photoshop "Multiply effects“?我在哪里可以找到一些这样的示例代码?我还看到了这个question
发布于 2012-04-22 05:49:52
如果您想要一种简单的方法,我的GPUImage框架有它的GPUImageMultiplyBlendFilter,它接受两个图像,并对每个像素逐个通道执行红色、绿色、蓝色和alpha通道乘法。它以GPU加速的方式完成此操作,因此它可以比在CPU上执行相同的操作快4-6倍。
要使用此功能,请将您的两个图像设置为混合:
UIImage *inputImage1 = [UIImage imageNamed:@"image1.jpg"];
GPUImagePicture *stillImageSource1 = [[GPUImagePicture alloc] initWithImage:inputImage1];
UIImage *inputImage2 = [UIImage imageNamed:@"image2.jpg"];
GPUImagePicture *stillImageSource2 = [[GPUImagePicture alloc] initWithImage:inputImage2];然后创建并配置您的混合过滤器:
GPUImageMultiplyBlendFilter *blendFilter = [[GPUImageMultiplyBlendFilter alloc] init];
[inputImage1 processImage];
[inputImage1 addTarget:blendFilter];
[inputImage2 addTarget:blendFilter];
[inputImage2 processImage];最后提取混合后的图像结果:
UIImage *filteredImage = [blendFilter imageFromCurrentlyProcessedOutput];在其当前实现中需要注意的一点是,比iPad 2旧的设备具有有限的纹理大小,因此现在无法在这些旧设备上处理大于2048x2048的图像。我正在努力解决这个问题。
发布于 2012-04-22 00:46:32
Multiply是一种( Adobe称之为)混合模式。混合模式本质上是使用一些数学公式的像素操作。您可以将两个图像混合在一起,也可以使用其中一个图像,从而实现“自混合”。
这可以通过逐个像素地对图像执行操作,通过获取特定像素的每个通道值并对其进行处理来实现。
不幸的是,我不熟悉Magick库。然而,这里有一个公式,给定一个通道值(红色、绿色或蓝色,0- 255),它将返回乘法运算的结果值。
unsigned char result = a * b / 255;
注意,a和b也必须是无符号字符,否则可能会发生溢出,因为结果会大于一个字节。这是基本的乘法公式,您可以通过分配更大的变量大小并适当修改除数来调整变量以支持每通道16位。
发布于 2014-06-06 21:10:47
重用Brad Larson代码对我来说效果很好。
UIImage *inputImage1 = [UIImage imageNamed:@"image1.jpg"];
GPUImagePicture *stillImageSource1 = [[GPUImagePicture alloc] initWithImage:inputImage1];
UIImage *inputImage2 = [UIImage imageNamed:@"sample.jpg"];
GPUImagePicture *stillImageSource2 = [[GPUImagePicture alloc] initWithImage:inputImage2];
GPUImageMultiplyBlendFilter *blendFilter = [[GPUImageMultiplyBlendFilter alloc] init];
[stillImageSource1 processImage];
[stillImageSource1 addTarget:blendFilter];
[stillImageSource2 addTarget:blendFilter];
[stillImageSource2 processImage];
[blendFilter useNextFrameForImageCapture];
UIImage *filteredImage = [blendFilter imageFromCurrentFramebuffer];
[self.imageView setImage:filteredImage];https://stackoverflow.com/questions/10260779
复制相似问题