我需要使用掩码从完整图像剪切并创建被屏蔽的图像.
@H_301_16@解决方法
=
我试过以下:
UIImage *imgMask = [UIImage imageNamed:@"Mask.png"]; UIImage *imgBgImage = [UIImage imageNamed:@"Full.png"]; GPUImageMaskFilter *maskingFilter = [[GPUImageMaskFilter alloc] init]; GPUImagePicture * maskGpuImage = [[GPUImagePicture alloc] initWithImage:imgMask ]; GPUImagePicture *FullGpuImage = [[GPUImagePicture alloc] initWithImage:imgBgImage ]; [maskGpuImage addTarget:maskingFilter]; [maskGpuImage processImage]; [maskingFilter useNextFrameForImageCapture]; [FullGpuImage addTarget:maskingFilter]; [FullGpuImage processImage]; UIImage *OutputImage = [maskingFilter imageFromCurrentFramebuffer];
请大家携手共进
干杯.
另外,谢谢BradLarson.
掩码是第二个目标,如在滤镜着色器代码(textureColor2)中可以看到的.
//Averages mask's the RGB values,and scales that value by the mask's alpha // //The dot product should take fewer cycles than doing an average normally // //Typical/ideal case,R,G,and B will be the same,and Alpha will be 1.0 lowp float newAlpha = dot(textureColor2.rgb,vec3(.33333334,.33333334,.33333334)) * textureColor2.a; gl_FragColor = vec4(textureColor.xyz,newAlpha);
然后,您需要在黑色背景上“反转”您的面具:白色心脏,因为过滤器使用RGB像素值的“重量”来设置目标图像上的alpha值.
所以你的代码应该是
// Image first,Mask next [FullGpuImage addTarget:maskingFilter]; [FullGpuImage processImage]; [maskingFilter useNextFrameForImageCapture]; [maskGpuImage addTarget:maskingFilter]; [maskGpuImage processImage];
和你的面具(好的,我做了一个丑陋的快速测试,使用正确的图像)像
预期结果.