我使用MWPhotoBrowser
显示UIImagePickerController
拍摄的照片
这是我保存到用户专辑的代码。
-(void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info
{
// NSDictionary* metadata=info[UIImagePickerControllerMediaMetadata];
// [[PHPhotoLibrary sharedPhotoLibrary]performChanges:^{
// NSURL* url=info[UIImagePickerControllerReferenceURL];
// PHAssetChangeRequest* assetChangeReques= [PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL:url];
// PHAssetCollectionChangeRequest* request=[PHAssetCollectionChangeRequest changeRequestForAssetCollection:self.assetCollection];
// [request addAssets:@[[assetChangeReques placeholderForCreatedAsset]]];
// }completionHandler:^(BOOL success,NSError* error){
// if (success) {
// // self.previewImgView.image=image;
// }
// }];
ALAssetsLibrary* alassetsLibary=[[ALAssetsLibrary alloc] init];
[alassetsLibary saveImageData:UIImageJPEGRepresentation(info[UIImagePickerControllerOriginalImage], 1.0f) toAlbum:self.assetCollection.localizedTitle metadata:info[UIImagePickerControllerMediaMetadata] completion:^(NSURL* assetUrl,NSError* error)
{
}failure:^(NSError* error){
}];
self.previewImgView.image=[info[UIImagePickerControllerOriginalImage] getThumbnailWithSize:self.previewImgView.bounds] ;
alassetsLibary=nil;
info=nil;
}
我已经习惯了保存上面的照片。但它无法解决与你的问题相同的问题
在第二种方法中。我试图将UIImageJPEGRepresentation
参数从0.1更改为1.0。但它确实起作用
我试着让alassetsLibary=nil; info=nil;
但是当我打开photoBrowser时。内存增长如此之快。
如果有人有解决方案,请告诉我!!
而且我想知道Apple如何处理本机相机应用中的这个问题
感谢。
答案 0 :(得分:0)
我总是使用此功能将照片保存到相册中:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:((UIImage *)[info objectForKey:UIImagePickerControllerEditedImage]).CGImage
metadata:[info objectForKey:UIImagePickerControllerMediaMetadata]
completionBlock:^(NSURL *assetURL, NSError *error) {
NSLog(@"assetURL %@", assetURL);
imageURL=[assetURL absoluteString];
//save URL for future use
[[NSUserDefaults standardUserDefaults] setObject:imageURL forKey:@"imageurl"];
}];
[picker dismissViewControllerAnimated:YES completion:NULL];
}