2011-08-24 93 views
0

我正在研究一個痤瘡應用程序,我必須從UIImagePicker中選擇圖像,並在向其添加子視圖之後,我想將它保存在相機膠捲中。將編輯後的圖像保存在相機膠捲上

問題:如果將UIImageView作爲子視圖添加到superView,pickerImage不會使用subView保存。

如果我將UIImage添加爲拾取器圖像的子視圖,我無法移動添加的UIImage視圖。

我使用下面的代碼保存圖像:

-(IBAction)savePhoto 
{ 


NSParameterAssert(imgToDisplayFromPicker.image); 
UIImageWriteToSavedPhotosAlbum(imgToDisplayFromPicker.image, nil, nil, nil); 


} 

回答

2

終於找到了解決方案:

CGRect contextRect = CGRectMake(6, 6, 302, 230); 

UIGraphicsBeginImageContext(contextRect.size); 

[self.view.layer renderInContext : UIGraphicsGetCurrentContext()]; 

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 

CGImageRef imageRef = CGImageCreateWithImageInRect([viewImage CGImage], contextRect); 

UIImage * newImage = [UIImage imageWithCGImage:imageRef scale:1.0 orientation:viewImage.imageOrientation]; 

UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil); 
相關問題