将图像从文件路径加载到资产库的UIImage [英] Load an image to UIImage from a file path to the asset library

查看:132
本文介绍了将图像从文件路径加载到资产库的UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与我之前的问题相关此处

Related to my previous question here.

我有资源库中图像的路径,例如:

I have a path to an image in the asset library , for example:

assets-library://asset/asset.JPG?id=1000000001&ext=JPG

现在,我如何将此路径中的图像加载到UIImage对象?

Now, how could I load the image from this path to a UIImage object?

以下是代码:

NSString *path = [occasion imagePath];

//temp
NSLog(@"the 2nd occasion imagePath is: %@", path);
//end

if (path != nil)
{
    //UIImage *image = [UIImage imageNamed:path];
    UIImage *image = [UIImage imageWithContentsOfFile:path];

    image = [image imageByScalingAndCroppingForSize:CGSizeMake(36.0, 42.0)];
    [[cell imageView] setImage:image];
}


推荐答案

来自我的链接上面的评论:

from the answer linked in my comment above:

    -(void)findLargeImage
{
    NSString *mediaurl = [self.node valueForKey:kVMMediaURL];

    //
    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
    {
        ALAssetRepresentation *rep = [myasset defaultRepresentation];
        CGImageRef iref = [rep fullResolutionImage];
        if (iref) {
            largeimage = [UIImage imageWithCGImage:iref];
            [largeimage retain];
        }
    };

    //
    ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
    {
        NSLog(@"booya, cant get image - %@",[myerror localizedDescription]);
    };

    if(mediaurl && [mediaurl length] && ![[mediaurl pathExtension] isEqualToString:AUDIO_EXTENSION])
    {
        [largeimage release];
        NSURL *asseturl = [NSURL URLWithString:mediaurl];
        ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
        [assetslibrary assetForURL:asseturl 
                       resultBlock:resultblock
                      failureBlock:failureblock];
    }
}

这篇关于将图像从文件路径加载到资产库的UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆