English 中文(简体)
如何从照片图书馆获得图像,以及如何从电话的照片图书馆检索图像?
原标题:How to get image path from photo library and how to retrieve the image from photo library in iphone?
  • 时间:2011-10-15 10:42:27
  •  标签:
  • iphone

I m New to iphone. 在我的小应用中,如何从照片图书馆获得图像。 我使用以下代码来拍摄图像并贴上图像。

-(IBAction) selectimage
{
UIImagePickerController *picker=[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
[picker release];
}
-(void) imagePickerController:(UIImagePickerController *)UIPicker didFinishPickingMediaWithInfo:(NSDictionary *) info
{
[UIPicker dismissModalViewControllerAnimated:YES];
imageview.image=[info objectForKey:"UIImagePickerControllerOriginalImage"];
    NSLog("Image Path=%@",imageview.image);
}

Its succefully placed to Imageview. But i cant get its imagepath. I m using nslog("%@",imageview.image); it shows "Image Path=" in console. How can i get its path and how to retrieve photos from photo library. Any body help me. Thanks in advance.

最佳回答

<代码>UIImagePickerController 原件Image只归还图像数据,而不提及其当地储存。 我用了这 myself,但我猜测你所期待的是什么。

NSURL* localUrl = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];

至少是我知道收回任何URL的唯一途径。

为检索图像,请查询。 问题:。 但是,也铭记,你已经掌握了图像。

UIImage* image=(UIImage*)[info objectForKey:@"UIImagePickerControllerOriginalImage"];

因此,请你真的需要。

问题回答

Swift 3.0, You can get imageData from referenceURL by following way

let url = URL(string: "assets-library://asset/asset.JPG?id=1000000007&ext=JPG")
let asset = PHAsset.fetchAssets(withALAssetURLs: [url], options: nil)
guard let result = asset.firstObject else {
  return nil
}
let imageManager = PHImageManager.default()
var imageData: Data? = nil
imageManager.requestImageData(for: result, options: nil, resultHandler: { (data, string, orientation, dict) in
  imageData = data
})




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签