简体   繁体   English

如何将png图像保存到相机胶卷中?

[英]How to save a png image to camera roll?

I'd like to save screenshots from my game to camera roll. 我想将游戏中的屏幕截图保存到相机胶卷中。 Right now I'm using UIImageWriteToSavedPhotosAlbum which saves the image in jpg format with way too much ugly jpg artifacts. 现在,我正在使用UIImageWriteToSavedPhotosAlbum,它将图像保存为jpg格式,并带有太多难看的jpg伪像。 Is there a way to save an UIImage in png format to camera roll? 有没有办法将png格式的UIImage保存到相机胶卷中?

First you have to add AssetsLibrary Framework, than like this: 首先,您必须添加AssetsLibrary Framework,而不是像这样:

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

UIImage *image = ... some image

[library writeImageDataToSavedPhotosAlbum: UIImagePNGRepresentation(image) metadata:nil completionBlock:nil];

The solution pointed out here is now deprecated - this post: 此处指出的解决方案现已过时-此帖子:

UIImageWriteToSavedPhotosAlbum saves to wrong size and quality UIImageWriteToSavedPhotosAlbum保存为错误的大小和质量

shows how to do this: 显示了如何执行此操作:

UIImage* im = [UIImage imageWithCGImage:myCGRef]; // make image from CGRef
NSData* imdata =  UIImagePNGRepresentation ( im ); // get PNG representation
UIImage* im2 = [UIImage imageWithData:imdata]; // wrap UIImage around PNG representation
UIImageWriteToSavedPhotosAlbum(im2, nil, nil, nil); // save to photo album

Napolit "I'd like to save screenshots from my game to camera roll. Right now I'm using UIImageWriteToSavedPhotosAlbum which saves the image in jpg format with way too much...." Napolit“我想将游戏中的屏幕截图保存到相机胶卷。现在,我正在使用UIImageWriteToSavedPhotosAlbum,它以太多的方式将图像保存为jpg格式。...”

Have just stumbled across your question, most of which I can't answer. 刚刚偶然发现了您的问题,其中大部分我无法回答。 however, I do have an EASY & QUICK WAY to grab iPad screens. 但是,我确实可以轻松快捷地获取iPad屏幕。 Simply press the SLEEP/WAKE button and the HOME (round button at bottom of the screen) button at the same time. 只需同时按下SLEEP / WAKE按钮和HOME(屏幕底部的圆形按钮)按钮即可。

这说明了如何将UIImage表示为jpg或png: 将UIImage对象另存为PNG或JPEG文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM