gpt4 book ai didi

objective-c - 将图像从 Assets 库的文件路径加载到 UIImage

转载 作者:IT王子 更新时间:2023-10-29 08:05:33 24 4
gpt4 key购买 nike

与我之前的问题相关here .

我在 Assets 库中有一张图片的路径,例如:

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

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

代码如下:

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];
}

最佳答案

来 self 上面评论中链接的答案:

    -(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];
}
}

关于objective-c - 将图像从 Assets 库的文件路径加载到 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8085267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com