从Iphone中的照片获取图像
我想按名称从iphone的gallery中获取图像。。 比如我在gallery one.png、two.png、three.png中有10张照片等等。 我想使用two.png。我怎样才能得到那个图像。并在我的UIImageView中使用它。从Iphone中的照片获取图像,iphone,objective-c,ios,Iphone,Objective C,Ios,我想按名称从iphone的gallery中获取图像。。 比如我在gallery one.png、two.png、three.png中有10张照片等等。 我想使用two.png。我怎样才能得到那个图像。并在我的UIImageView中使用它。 这可能吗 imagePickerController:(UIImagePickerController*)picker没有用info:(NSDictionary*)完成PickingMediaWithInfo: 用这种方法写 UIImage *image =
这可能吗
imagePickerController:(UIImagePickerController*)picker没有用info:(NSDictionary*)完成PickingMediaWithInfo:
用这种方法写
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[ImageViewName setImage:image];
[picker1 dismissViewControllerAnimated:YES completion:nil];
用于从photolibrary中拾取图像,您可以使用 如果您有图像的assetlibrary url,则可以使用以下代码:
typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [myasset aspectRatioThumbnail];
UIImage *images;
if (iref)
{
images = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];
}
else
{
images = [UIImage imageNamed:@"Noimagey.png"];
}
dispatch_async(dispatch_get_main_queue(), ^{
yourImageView.contentMode = UIViewContentModeScaleAspectFit;
[yourImageView setImage:images];
});
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
UIImage *images = [UIImage imageNamed:@"Nofile.png"];
dispatch_async(dispatch_get_main_queue(), ^{
[yourImageView setImage:images];
});
};
NSURL *asseturl = [NSURL URLWithString:yourAssetUrl];
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:asseturl resultBlock:resultblock failureBlock:failureblock];
如果使用资源库拾取图像,请始终记住:
我不想使用imagePicker。@Zohaib这是您创建的静态图像库?假设我用temp.png保存了图像。现在,从assetlibrary获取图像的url是什么?这是一个任意url,如:assets-library://asset/asset.JPG?id=1000000003&ext=JPGyou 无法使用名称将图像保存到photolibrary。当我保存图像时,如何知道为该图像生成的id。我可以用id访问该图像吗?@Zohaib:如果您使用的是
-(void)writeImageToSavedPhotosAlbum:(cImageRef)imageRef方向:(ALAssetOrientation)方向完成块:(AlasSetLibrary WriteImageCompletionBlock)completionBlock
方法然后您将从完成块参数中获取url。您只需要图像还是图像+视频现在我无法回答…:(