UIImagePNG表示和蒙版图像
我使用 创建了一个蒙版图像功能形成一个iphone博客:
UIImage *imgToSave = [self maskImage:[UIImage imageNamed:@"pic.jpg"] withMask:[UIImage imageNamed:@"sd-face-mask.png"]];
在 UIImageView 中看起来不错
UIImageView *imgView = [[UIImageView alloc] initWithImage:imgToSave]; imgView.center = CGPointMake(160.0f, 140.0f); [self.view addSubview:imgView];
UIImagePNGRepresentation 保存到磁盘:
[UIImagePNGRepresentation(imgToSave) writeToFile:[self findUniqueSavePath] 原子地:YES];
UIImagePNGRepresentation 返回看起来不同的图像的 NSData。
输出是逆图像掩模。 在应用程序中剪切的区域现在在文件中可见。 应用程序中可见的区域现已删除。可见性相反。
我的面具旨在去除图片中除面部区域之外的所有内容。 UIImage 在应用程序中看起来正确,但将其保存到磁盘后,文件看起来相反。脸部已被移除,但其他一切都在那里。
如果您能提供帮助,请告诉我!
I created a masked image using a function form an iphone blog:
UIImage *imgToSave = [self maskImage:[UIImage imageNamed:@"pic.jpg"] withMask:[UIImage imageNamed:@"sd-face-mask.png"]];
Looks good in a UIImageView
UIImageView *imgView = [[UIImageView alloc] initWithImage:imgToSave]; imgView.center = CGPointMake(160.0f, 140.0f); [self.view addSubview:imgView];
UIImagePNGRepresentation to save to disk:
[UIImagePNGRepresentation(imgToSave) writeToFile:[self findUniqueSavePath] atomically:YES];
UIImagePNGRepresentation returns NSData of an image that looks different.
The output is inverse image mask.
The area that was cut out in the app is now visible in the file.
The area that was visible in the app is now removed. Visibility is opposite.
My mask is designed to remove everything but the face area in the picture. The UIImage looks right in the app but after I save it on disk, the file looks opposite. The face is removed but everything else this there.
Please let me know if you can help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在石英中,您可以通过图像掩模(黑色透光和白色块)或正常图像(白色透光和黑色块)来进行凸轮掩模,这是相反的。似乎出于某种原因,保存将图像蒙版视为要蒙版的普通图像。一种想法是渲染到位图上下文,然后创建要从中保存的图像。
In quartz you cam mask either by an image mask (black let through and white blocks), or a normal image (white let through and black blocks) which is the opposite. It seems for some reason saving is treating the image mask as a normal image to mask with. One thought is to render to a bitmap context and then create an image to be saved from that.
我遇到了完全相同的问题,当我保存文件时,这是一种方式,但内存中返回的图像完全相反。
罪魁祸首&解决方案是 UIImagePNGRepresentation()。它在将应用内图像保存到磁盘之前修复了该图像,因此我只是插入该函数作为创建蒙版图像并返回该图像的最后一步。
这可能不是最优雅的解决方案,但它确实有效。我从我的应用程序中复制了一些代码并将其压缩,不确定下面的代码是否按原样工作,但如果不能,则其关闭......也许只是一些拼写错误。
享受。 :)
I had the exact same issue, when I saved the file it was one way, but the image returned in memory was the exact opposite.
The culprit & the solution was UIImagePNGRepresentation(). It fixes the in-app image before saving it to disk, so I just inserted that function as the last step in creating the masked image and returning that.
This may not be the most elegant solution, but it works. I copied some code from my app and condensed it, not sure if this code below works as is, but if not, its close... maybe just some typos.
Enjoy. :)