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
Now, how could I load the image from this path to a UIImage object?
Here is the code:
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];
}
Once a UIImage is created, the image data is loaded into memory and no longer connected to the file on disk. As such, the file can be deleted or modified without consequence to the UIImage and there is no way of getting the source path from a UIImage.
UIImage *img = [UIImage imageNamed:@"anyImageName"];
An object that manages image data in your app.
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .
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];
}
}
Try the following:
(UIImage *)imageWithContentsOfFile:(NSString *)path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With