Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios4 将编辑后的图像保存在摄影机卷中_Ios4_Uiimageview_Save_Uiimagepickercontroller_Edit - Fatal编程技术网

Ios4 将编辑后的图像保存在摄影机卷中

Ios4 将编辑后的图像保存在摄影机卷中,ios4,uiimageview,save,uiimagepickercontroller,edit,Ios4,Uiimageview,Save,Uiimagepickercontroller,Edit,我正在开发一个痤疮应用程序,在这个应用程序中,我必须从UIImagePicker中选择图像,在添加子视图后,我想将其保存在camera roll中 问题:如果将UIImageView作为子视图添加到superView,则pickerImage不会随子视图一起保存 如果我将UIImage作为子视图添加到选择器图像中,则无法移动添加的UIImage视图 我使用以下代码保存图像: -(IBAction)savePhoto { NSParameterAssert(imgToDisplayFromPi

我正在开发一个痤疮应用程序,在这个应用程序中,我必须从UIImagePicker中选择图像,在添加子视图后,我想将其保存在camera roll中

问题:如果将UIImageView作为子视图添加到superView,则pickerImage不会随子视图一起保存

如果我将UIImage作为子视图添加到选择器图像中,则无法移动添加的UIImage视图

我使用以下代码保存图像:

-(IBAction)savePhoto
{


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


}

最终找到了解决方案:

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);