Xcode iOS生成.png文件并使用NSFileManager保存
我正在制作一个iOS应用程序,我得到了一个UIImage-我想把它压缩成.png文件并保存到应用程序的documents文件夹中-我已经有了路径,我所需要的就是如何将UIImage转换成.png并保存它 谢谢, 马坦。巴布亚新几内亚:Xcode iOS生成.png文件并使用NSFileManager保存,ios,objective-c,nsfilemanager,Ios,Objective C,Nsfilemanager,我正在制作一个iOS应用程序,我得到了一个UIImage-我想把它压缩成.png文件并保存到应用程序的documents文件夹中-我已经有了路径,我所需要的就是如何将UIImage转换成.png并保存它 谢谢, 马坦。巴布亚新几内亚: UIImagePNGRepresentation 以PNG格式返回指定图像的数据 NSData * UIImagePNGRepresentation ( UIImage *image ); 如果您想要JPEG格式: UIImageJPEGReprese
UIImagePNGRepresentation
以PNG格式返回指定图像的数据
NSData * UIImagePNGRepresentation (
UIImage *image
);
如果您想要JPEG格式:
UIImageJPEGRepresentation
以JPEG格式返回指定图像的数据
NSData * UIImageJPEGRepresentation (
UIImage *image,
CGFloat compressionQuality
);
因此,代码是:
UIImage *yourImage = ...; //the image you have
NSString *targetPath = ...; // something like ~/Library/Documents/myImage.png
[UIImagePNGRepresentation(yourImage) writeToFile:targetPath atomically:YES];
图像压缩格式是JPEG,您可以使用不同质量的jpg图像
// for getting png image
NSData*theImageData=UIImagePNGRepresentation(theImage);
// for JPG compression change fill value between less than 1
NSData*theImageData=UIImageJPEGRepresentation(theImage, 1);
// for converting raw data image to UIImage
UIImage *imageOrignal=[UIImage imageWithData:theImageData];
// for saving in to photos gallery
UIImageWriteToSavedPhotosAlbum(imageOrignal,nil,nil,nil);
非常感谢!很好用!有没有压缩png的方法?没有。你可以包括pngcrush源。但框架中没有任何内容