2012-06-13 69 views
0

我用像下列代碼將當前屏幕保存到圖片庫:控制圖像質量UIImageWriteToSavedPhotosAlbum

UIGraphicsBeginImageContext(self.view.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();  
UIGraphicsEndImageContext(); 
UIImageWriteToSavedPhotosAlbum(result, nil,nil, nil); 

這工作,但質量看起來很像一個壓縮JPG(文件保存的名稱採用標準的IMG_XXXX.JPG格式),即使此代碼中沒有指定圖像的類型或其質量。有沒有辦法來控制質量?即我可以將它保存爲未壓縮的PNG嗎?

回答

2

可以利用UIImagePNGRepresentation()方法將其保存爲PNG爲NSData,做這樣的事情:

.... 
UIImage* result = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
NSData* data = UIImagePNGRepresentation (result); 
UIImage* pngImage = [UIImage imageWithData:data]; 
UIImageWriteToSavedPhotosAlbum(pngImage, nil, nil, nil); 

希望這有助於。