我在现有的UIImage周围添加一个相框(具有透明背景的图像),并将其全部保存为一个图像。在模拟器上,一切看起来都运行良好。但是,在设备上,它会在帧图像的某些区域周围添加一些白色像素。这是我的代码:
- (void)applyFilter {
NSLog(@"Running");
UIImage *borderImage = [UIImage imageNamed:@"IMG_8055.PNG"];
NSData *dataFromImage = UIImageJPEGRepresentation(self.imgView.image, 1);
CIImage *beginImage= [CIImage imageWithData:dataFromImage];
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *border =[CIImage imageWithData:UIImagePNGRepresentation(borderImage)];
border = [border imageByApplyingTransform:CGAffineTransformMakeScale(beginImage.extent.size.width/border.extent.size.width, beginImage.extent.size.height/border.extent.size.height)];
CIFilter *filter= [CIFilter filterWithName:@"CISourceOverCompositing"]; //@"CISoftLightBlendMode"];
[filter setDefaults];
[filter setValue:border forKey:@"inputImage"];
[filter setValue:beginImage forKey:@"inputBackgroundImage"];
CIImage *outputImage = [filter valueForKey:@"outputImage"];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg];
self.imgView.image = newImg;
}
这是结果图像:
图片中使用的框架图像如下所示:
这是photoshop中帧图像的屏幕截图,显示了PNG中不存在的那些像素。
The issue is that if you look at your image, those pixels immediately adjacent to the musical notes are apparently not transparent. And if you notice, those white pixels that appear in the final image aren't just the occasional pixel, but they appear in square blocks.
These sorts of squared-off pixel noise is a telltale sign of JPEG artifacts. It's hard to say what's causing this because the image you added to this question was a JPEG (which doesn't support transparency). I assume you must have a PNG version of this backdrop? You might have to share that with us to confirm this diagnosis.
但最重要的是,您需要仔细检查原始图像和那些看似白噪声的像素的透明度。确保在创建/处理这些图像时,避免使用JPEG文件格式,因为它会丢失透明度信息并引入伪影。PNG文件通常更安全。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句