在 ipad 上使用
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
方法不给出图像。信息字典是
> 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 获取的图像的方向。谢谢你