iphone: UIImagePickerController how to get the thumbnail for the picker control - iphone

Hello I need to use the uiimagepickercontroller to get the photo from the photo library in IOS 3. I managed to get the original image and custom coding to generate the thumbnail from the original image.
Is there a way of fetching the thumbnail that was used in the UIImagePickerController? I can generate thumbnail from original image but it will slow down the whole process. At the time, is there a way of saving the url of the original image. At the moment, I am just create a new image and saved on a temporary folder for later app to upload the server. The process is too slow since I need to generate thumbnail as well as creating the original image.

in ios 3.0 , their is no direct way to get thumbnail, you have to do custom coding to get thumbnail .
from version 4.0 we have ALAssetsLibrary.
ALAssetsLibrary *assetslibrary = [self defaultAssetsLibrary];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){
CGImageRef thumbnailRef = [myasset thumbnail]; //gives thumbnail
}
[assetslibrary assetForURL:asseturl resultBlock:resultblock failureBlock:^(NSError *error) {
//handle error
}];
but cons of above method is if used declined access to library then you have to handle error and again get thumbnail again with custom coding .
please update if you have find any better method .

Related

How to set image in UIImageView from image of audio file in AVAudioPlayer?

I want to make basic Audio Player app by programatically.
If every Audio file contain image then I want that in UIImageView automatically set image from audio file.
If any file doesn't contain any image file then it should be set default image.
Like i shown below:
check how you are taking those images.
-case its Networking, use SDWebImage, take a look here:
https://github.com/rs/SDWebImage
-case those images are saved in a core data (example) make a search in your data, if exists,
pick that data and convert it to an image
UIImage * image = [UIImage imagewithData:dataImage];
remember you need to have a database image online or offline. Then just make a search, case exists, put the image, case not, default image.
The code that you need can be found in Apple's Example as referenced in the question that overbombing referenced. They make it easy for you:
MPMediaItem *currentItem = [musicPlayer nowPlayingItem];
// Assume that there is no artwork for the media item.
UIImage *artworkImage = noArtworkImage;
// Get the artwork from the current media item, if it has artwork.
MPMediaItemArtwork *artwork = [currentItem valueForProperty: MPMediaItemPropertyArtwork];
// Obtain a UIImage object from the MPMediaItemArtwork object
if (artwork) {
artworkImage = [artwork imageWithSize: CGSizeMake (30, 30)];
}
I would advise reading through Apple's Example anyway it seems you are doing pretty much exactly what they did.

Loading camera roll images in iOS GridView very slow

I am showing all the images from the camera roll in my iPhone app. I build an array of ALAsset * that contains the list of all images in the camera roll when the app starts. I form cells by loading these images in a image view:
// Get the full resolution image for asset
ALAssetRepresentation *assetRep = [asset defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[assetRep fullResolutionImage]];
[cell.imageCropper setImage:image];
I do this when a new cell is requested in
- (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSUInteger) index
The problem is that it lags when there are many images and the user scrolls quickly through the images. What is the correct way of handling this?
Consider loading the images in the background using GCD.
Maybe this helps: loading images from a background thread using blocks
Use thumbnail instead of fullResolutionImages

iOS, Getting a handle on an image just taken with the device's camera

Could anyone perhaps tell me how exactly I could get a handle on an image that the user has just taken with the device camera? For instance, when the user captures an image, it is saved to the photo library, but you don't know the exact name of the image file without going to the photo library an searching for the image. I want to get a handle on the image once it is taken and then pass it to an UIImage so that I could for instance immediately display it to the user.
Thank you
You have 2 options depending on what method you are using to capture the image.
If you are using the UIImagePickerController to capture a still image with the UIImagePickerControllerSourceTypeCamera set as the source. You will recieve a call to your DELEGATE when the picture has been taken.
- (void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info
Here you can find the picture which you can use to present it directly. (The picture is in the "info" dictionary)
https://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/TakingPicturesAndMovies.html#//apple_ref/doc/uid/TP40010406
Check the code on that apple site to see how it is implemented.
Alternatively method number 2 is by using the AVFoundation Framework. However this requires you to configure much more even though it gives you more freedom to how you can set things.
At the end of the implementation you will get the picture like this:
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:
^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
CFDictionaryRef exifAttachments =
CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
if (exifAttachments) {
// Do something with the attachments.
}
// Continue as appropriate.
}];
Here the image is in the imageSamplerBuffer.
This approach can be found here: https://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html

How Do I speed Up Image Loading Using The Assets Library?

I am writing an app that is a clone of the UIImagePicker but uses the Assets library. When the user selects a photo, it takes a little bit too long for the image to load. I notice that when I use the photos app which has identical functionality as to what I'm developing, that the image loading is a bit faster. I've heard another responder on this site mention the following in order to mimic the functionality of the photos app:
"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."
Does anyone have any code samples of how this can be accomplished? I'm not quite sure that I understand what he means.
Also here is my code for which I'm using to load an image (I'm passing the image as a parameter to another view controller):
myImage = [UIImage imageWithCGImage:[[myAsset defaultRepresentation] fullScreenImage]];
The class ALAsset has two methods to obtain thumbnails:
- (CGImageRef)thumbnail
- (CGImageRef)aspectRatioThumbnail
I bet they are faster than obtaining the full screen sized version of the asset.
Also, you can wrap them with an async operation. Be sure to update the UI in main thread. Roughly like this:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
/* obtain the image here */
dispatch_async(dispatch_get_main_queue(), ^{
/* update screen here */
});
[pool drain];
});
If you need to obtain thumbnails for videos you should use AVAssetImageGenerator. It has a method to obtain them asynchronously.
Look for Apple sample code (AVEditDemo and probably others working with assets library).

iPhone: Save image to a specific photo album

The application I am working on manipulates an image for a user, and after the user is done, they can save that photo. I have no problem capturing the screen and saving it (as I want some of the labels saved with the image) but this call:
UIImageWriteToSavedPhotosAlbum([self getScreenAsImage] , nil, nil, nil);
only appears to allow me to save to the 'Saved Photos' album. Ideally I would like to create an album named after the application I am working on and save it there so that they are all stored together (for example like the Hawaii or graduation day albums on the simulator). It would also be nice then to launch the image picker in that specific album. Anyone know how to do this? Most important part is to be able to save it in an album, being able to launch the picker in that album is of secondary importance.
There is a way to do it, Apple just hasn't made it simple.
There is a custom category that adds the functionality to ALAssetsLibrary.
Git repo for the category can be found here
and if you are using Cocoapods you can get it with
pod 'ALAssetsLibrary-CustomPhotoAlbum'
You will need to instantiate a ALAssetsLibrary object and call the method below
- (void)saveImage:(UIImage *)image
toAlbum:(NSString *)albumName
completion:(ALAssetsLibraryWriteImageCompletionBlock)completion
failure:(ALAssetsLibraryAccessFailureBlock)failure
Something like below
Import:
#import "ALAssetsLibrary+CustomPhotoAlbum.h" //Source Included (Git)
or
#import <ALAssetsLibrary+CustomPhotoAlbum.h> //Cocoapods
Call:
ALAssetsLibrary *assetsLib = [[ALAssetsLibrary alloc] init];
[assetsLib saveImage:imageToSave
toAlbum:#"AlbumName"
completion:completionBlock
failure:failureBlock];
You can use the ALAssetsLibrary for doing this:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library saveImage:image toAlbum:#"Midhun" withCompletionBlock:^(NSError *error) {
if (error!=nil) {
NSLog(#"Error: %#", [error description]);
}
}];
Check this tutorial also: Custom Photo Album
To the best of my knowledge Apple has not exposed an SDK to allow for this. After a review the UIKit function reference, My fear seems confirmed.