- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
メソッドを使用
するiPadでは、画像を提供しないでください。情報辞書は
> dic = {
> UIImagePickerControllerMediaType = "public.image";
> UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=1D8618CC-CDF1-478C-A36D-455A66501A02&ext=JPG";
> }
だから私はこの質問で答えたようにreferenceURLを使用しました。そのための私のコードは
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
editPhoto=YES;
[self dismissModalViewControllerAnimated:YES];
NSLog(@"dic = %@",info);
defaultImageView.image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
if(defaultImageView.image == nil)
{
NSLog(@"image from assets");
NSURL *imageSource = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
[self findLargeImage:imageSource];
}
NSLog(@"image picked in block");
}
-(UIImage*)findLargeImage :(NSURL*)path
{
__block UIImage * largeimage=nil;
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref) {
largeimage =[UIImage imageWithCGImage:iref];
defaultImageView.image = [ImageOreintation fixOrientation:largeimage];
int width = defaultImageView.image.size.width;
int height = defaultImageView.image.size.height;
int frameWidth = (158.0/height) * width;
if(frameWidth>212)
{
defaultImageView.frame = CGRectMake(26, 10, 212, 158);
}
else
{
defaultImageView.frame = CGRectMake(132-frameWidth/2, 10, frameWidth, 158);
}
NSLog(@"in find large image3");
}
};
NSLog(@"in find large image4");
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"booya, cant get image - %@",[myerror localizedDescription]);
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:path resultBlock:resultblock failureBlock:failureblock];
return largeimage ;
}
この方法で画像を取得しますが、画像の向きは上下逆です。
ピッカーから直接画像を取得するか、URL から取得した画像の方向を変更するのに役立ちます。ありがとうございました