-1

在我的 iPad 应用程序中,用户从webView. 保存的图像以imagePicker包含在UIPopOver. 用户可以裁剪和调整图像大小,完成后,所选图像以UIImageView.

所有这一切都很好,但要实现它,webView使用以下代码将从中选择的图像加载到用户的库中:

imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

理想情况下,我不希望将图像保存到库中,因为应用程序完成后将不需要或保存图像。如果有帮助,这是我用来将图像从webView库中获取的代码:

UIGraphicsBeginImageContext(webPage.frame.size);
[webPage.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil,nil,nil);
4

1 回答 1

1

然后将其保存到NSDocumentsDirectory

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *docs = [paths objectAtIndex:0];
    NSString *picture_information = [docs stringByAppendingFormat:@"/picture_name.png"];

//your code

UIGraphicsBeginImageContext(webPage.frame.size);
[webPage.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[UIImagePNGRepresentation(viewImage) writeToFile:picture_information atomically:YES];

//And you retrieve it like this:

 UIImage *img = [UIImage imageWithContentsOfFile:picture_information];

希望这可以帮助。

于 2013-07-06T14:31:23.543 回答