2010-03-08 75 views

回答

1

我不知道如何做到这一点的SDK,但是虽然UI,如果复制+粘贴图像转化成消息,它保持其全尺寸。也许在SDK中有这样的机制(复制到剪贴板)?不知道。希望它给你一个想法。

3

功能

 
 
NSData * UIImageJPEGRepresentation (
    UIImage *image, 
    CGFloat compressionQuality 
); 
 

使你得到你的图像的数据表示了预期的压缩质量(1为最佳)。

然后,您只需将NSData写入文件系统即可获取JPEG文件(例如,使用NSData上的writeToURL:atomically:)。

同样可以应用于.PNG与UIImagePNGRepresentation

原DOC: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/c/func/UIImageJPEGRepresentation

+0

NSData * imageData = UIImagePNGRepresentation(img1); 我通过NSData获得我的照片。如何保存照片? – Naeim 2010-03-11 12:33:32

6

你需要用图像中的PNG表示,因此,它的保存到图片库中PNG格式,而不是JPG格式。

我用以下代码根据Ben Weiss的代码:UIImageWriteToSavedPhotosAlbum saves to wrong size and quality进行并排比较。

// Image contains a non-compressed image stored within my Documents directory 
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); 
NSData* imdata = UIImagePNGRepresentation (image); 
UIImage* im2 = [UIImage imageWithData:imdata]; 
UIImageWriteToSavedPhotosAlbum(im2, nil, nil, nil); 

图片将以照片库中的PNG格式保存,以便以后可以以完整质量访问/共享。

相关问题