将屏蔽的 UIImage 保存到磁盘会产生错误的图像
我有一个带有大量蒙版图像的应用程序。为了提高性能,我需要在磁盘上生成这些屏蔽图像,然后将它们合并到应用程序中(它们将按需上传,而不是动态屏蔽,因为它已经完成了)。
我正在使用这种编码
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/Test_%d.png",i]];
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/Test_%d.jpg",i]];
// Write a UIImage to JPEG with minimum compression (best quality)
// The value 'image' must be a UIImage object
// The value '1.0' represents image compression quality as value from 0.0 to 1.0
[UIImageJPEGRepresentation([self maskImageWithStroke:image withMask:maskImage], 1.0) writeToFile:jpgPath atomically:YES];
// Write image to PNG
[UIImagePNGRepresentation([self maskImageWithStroke:image withMask:maskImage]) writeToFile:pngPath atomically:YES];
,它非常适合我的中间图像,但不适用于最终图像。
这是我使用的多个掩模和空白的过程:
拍摄图像并将其掩模到 获取 maskedImage
列表项获取掩码并稍微调整其大小 更大:更大的掩码
混合maskedImage和更大的掩码 拥有 maskedStrokeImage 由 biggrMask 抚摸(这是 我发现添加不规则的唯一方法 不规则蒙版上的描边 image)
掩码 maskedStrokeImage 与 更大的面具以获得我的最终结果 结果。
问题是:保存在步骤 1 中获得的图像是可以的:我有一个 JPG 和 PNG 正是我所需要的。
我的目标是将步骤 4 的结果保存到磁盘,但结果是一个显示笔画某些部分的 imahe,其余部分是白色的...
知道为什么我无法将步骤 4 保存到磁盘吗?
I've an app with a lot of masked image. For performance sake I ned to generate those masked image on disk and then incorporate them in the app (they'll be uploaded on demand nut not masked on the fly because it is already done).
I'm using this kind of coding
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/Test_%d.png",i]];
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/Test_%d.jpg",i]];
// Write a UIImage to JPEG with minimum compression (best quality)
// The value 'image' must be a UIImage object
// The value '1.0' represents image compression quality as value from 0.0 to 1.0
[UIImageJPEGRepresentation([self maskImageWithStroke:image withMask:maskImage], 1.0) writeToFile:jpgPath atomically:YES];
// Write image to PNG
[UIImagePNGRepresentation([self maskImageWithStroke:image withMask:maskImage]) writeToFile:pngPath atomically:YES];
and it works perfectly for my intermediate images but not with the final one.
Here is the process of multiple mask and blan I use :
take an image and mask it to
obtain the maskedImageList item take the mask and resize it a bit
bigger : biggerMaskblend maskedImage and biggermask
to have the maskedStrokedImage
stroked by biggrMask (this is the
only way I found to add an irregular
stroke on the irregular masked
image)mask maskedStrokedImage with
biggerMask to obtain my final
result.
The problem is : saving the image obtained on step 1 is ok : I've got a JPG and PNG with exactly what I need.
My goal is to save the result of step 4 to disk but the result is an imahe showing some part of the stroke and the rest is white ...
Any Idea why I'm unable to save the step 4 to disk ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里找到解决方案 https://devforums.apple.com/thread/67565?tstart=0< /a>
在透明背景上使用黑色形状的蒙版,并使用以下方法。蒙版图像完美保存到磁盘,并且可以按原样导入到屏幕,它保持透明度......太棒了!
Solution found here https://devforums.apple.com/thread/67565?tstart=0
use mask with black shape on transparent background and use the following method. The masked inmage is saved perfectly to disk and can be imported as is to the screen it keeps its transparency ... grooovy !!!