關於ipad使用 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
方法不給圖像。信息詞典didFinishPickingMediaWithInfo返回的圖片:在ipad上
> dic = {
> UIImagePickerControllerMediaType = "public.image";
> UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=1D8618CC-CDF1-478C-A36D-455A66501A02&ext=JPG";
> }
所以我用referenceURL在this問題asnwered。 我的代碼是
-(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獲取圖像的方式。 謝謝
http://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more - >有一些關於如何獲得UIImage對象的提示。 「如何調整圖像大小」的方法2也修復了方向。 – Marc