2010-03-08 73 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格式保存,以便以後可以以完整質量訪問/共享。

相關問題