Using AssetsLibrary Framework loading images too slow - iphone

I am just using AssetsLibrary Framework to load images from Photos.
[UIImage imageWithCGImage:[asset defaultRepresentation].fullScreenImage scale:1.0 orientation:(UIImageOrientation)[asset defaultRepresentation].orientation];
It will take about 0.5~0.6 second to get one photo. And the photo is not that large (for about 700*900).
Am I using the method in a wrong way? And can it be optimized?
(I want the photo of this size, do not want the thumbnail)
Many thanks!

you are using the method correctly. An idea to optimize the user-experience:
=> Load the thumbnail image first (best with dispatch_async) - that should be really quick. When this has completed, load the fullscreen image like you did above.
This is what apple does in the Photo App to provide a smooth user experience.
Cheers,
Hendrik

Related

iPhone Image Loading in Photos Application

I am not sure if this is the right forum for asking this question, but I googled "questions related to iPhone" and the first page had SO from top to bottom. So here goes.
When I open the Photos Application in iPhone (3GS, 4 and 5 all running iOS 5.0) and open an image, first a blurred image appears for a fraction of a second, which clears up into the actual picture. My question is, does the Photo application have a low resolution copy of the high res images which it displays while the image is being loaded, OR does it generate a low res image on the fly before going on to load the high res image.
I am writing an application to browse through the photos, and need to know which is the best approach. That is the purpose behind this question.
The best way is using ALAsset thumbnail . If you have concerns with image clarity, then go with ALAsset fullResolutionImage
Here are some details that you must read before going to start developing an photos application.
An instance of ALAssetsLibrary provides access to the videos and photos that are under the control of the Photos application.
An ALAsset object represents a photo or a video managed by the Photo application.
There are different ALAsset Accessing Representations
1.thumbnail
Returns a thumbnail representation of the asset.
- (CGImageRef)thumbnail
2.aspectRatioThumbnail
Returns an aspect ratio thumbnail of the asset.
- (CGImageRef)aspectRatioThumbnail
3.defaultRepresentation
Returns an asset representation object for the default representation.
- (ALAssetRepresentation *)defaultRepresentation
4.representationForUTI:
Returns an an asset representation object for a given representation UTI.
- (ALAssetRepresentation *)representationForUTI:(NSString *)representationUTI
An ALAssetRepresentation object encapsulates one of the representations of a given ALAsset object.
1.CGImageWithOptions:
Returns a full resolution CGImage of the representation.
- (CGImageRef)CGImageWithOptions:(NSDictionary *)options
2.fullResolutionImage
Returns a CGImage representation of the asset.
- (CGImageRef)fullResolutionImage
3.fullScreenImage
Returns a CGImage of the representation that is appropriate for displaying full screen.
- (CGImageRef)fullScreenImage
Sample Code

How to prevent images saved to photo library from being resized/scaled to full screen?

Here is the deal, I have tried using both of the methods shown below to save an image to the photo library. Upon saving the image successfully and launching the Photos App to take a look at the image, the app automatically scales/resizes the image to full screen.
Is there any way to prevent this? It is annoying because to see the whole image the user needs to pinch the image out to show the whole thing. I have noticed a few of the more popular camera apps do not have this issue when saving to the photo library. I am curious what method they are using.
//Save to Photo Library;
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
//CIImage *ciImage = image.CIImage;
[library writeImageToSavedPhotosAlbum:finalImage.CGImage
orientation:ALAssetOrientationUp
completionBlock:^(NSURL *assetURL, NSError *error) {
NSlog(#"Done");
}];
Save to Photo Library;
UIImageWriteToSavedPhotosAlbum(savedPhoto,nil,nil,nil);
Thank you for your help!
After doing a bit of research there is no solution to this problem. The photos app automatically scales up the image to fill the screen.
Thanks for all of the responses.
Saving image should be fine.
I think you can set UIView property UIViewContentMode, when you using the image.
typedef enum {
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent
UIViewContentModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped.
UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)
UIViewContentModeCenter, // contents remain same size. positioned adjusted.
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
} UIViewContentMode;
Hope it helps.
If you take a look at the FrogScroller sample application from Apple, you'll see they initially load a low-resolution of the image first and then, when zooming use a CATiledLayer with it's size set by the setMaxMinZoomScalesForCurrentBounds function.
You might want to look at WWDC 2010's video on scrollViews as well as 2011 for more info. Josh and Eliza do a great job explaining what's up.
Why not layer the image onto a fullscreen image with a clear background before saving?

how to get iphone ipod playlist images and display it in image view

I am working with iphone ipod to read the album and playlist and play it in my application.
My question is that that i get the image from the album i have selected. and it is also working well in my application.
But i never get images from the playlist which i have selected their are different songs in my playlist and also having different image for that songs. for the album i have get the code and it work great. i am new for this and i cant found any reference code for this.
And i am using AVPlayer to play the songs.
So please help me and provide some sample code. for how to get all images from playlist and convert that image to data in iphone.
Please help me.
You're looking for is the MPMediaItemPropertyArtwork for MPMediaItem. As stated in the docs. After getting the artwork property you can make a MPMediaItemArtwork object, as stated in the docs.
An MPMediaItemArtwork object, or media item artwork, represents a graphical image, such as music album cover art, associated with a media item. Media items are described in MPMediaItem Class Reference.
With this you can do something like this. Assuming song is an MPMediaItem:
UIImage *image = nil;
MPMediaItemArtwork *itemArtwork = [song valueForProperty:
MPMediaItemPropertyArtwork];
if(itemArtwork != nil)
image = [itemArtwork imageWithSize:CGSizeMake(100,100)];
Now you have image containing your MPMediaItem artwork, set it to your image view ([myImageView setImage:image]). Keep in mind, this will only work if artwork IS available.
Hope this helps.
You can use VTM_AViPodReader demo for this.

How to save images in camera roll in iphone programmatically?

I am developing one application. In that I want to save my pictures in camera roll. So how to save my pictures in camera roll through code?
The most basic way (and the only way if you're targeting iOS before 4.0) is to use UIImageWriteToSavedPhotosAlbum. This lets you specify a selector to be called on a target object when the save is complete.
In 4.0, you can use ALAssetsLibrary's writeImageToSavedPhotosAlbum:orientation:completionBlock: to write the image; in this case, you provide a block to be called when the save is complete.
In 4.1, you can also use ALAssetsLibrary's writeImageDataToSavedPhotosAlbum:metadata:completionBlock: or writeImageToSavedPhotosAlbum:metadata:completionBlock: to write an image along with metadata (e.g. geotagging information). The former is also the only way to write an image from an NSData object without first loading it as a UIImage or CGImageRef.
See this blog post..UIImageWriteToSavedPhotosAlbum is your friend..

Iphone - Load image from camera roll to UIImageView without UIImagepicker

Is it possible to load the last photo from camera roll to UIImageView without using a UIImagepicker?
I mean retrieve the path to the file or something like that.
Thankz :D
You should be able to do this by using the new AVFoundation framework. You may want to take a look at the WWDC 2010 session videos discussing the framework and the related source code.