Setting a UIImageView with ALAsset - iphone

I have a UIImageView and would like to set it to the contents of an ALAsset.
How is the ALAssets contents used to set a UIImage?

Try this. Asset is ALAsset by the way.
UIImage *image = [UIImage imageWithCGImage:[asset thumbnail] scale:1.0 orientation:[[asset defaultRepresentation] orientation]]
UIImageView *image_view = [[UIImageView alloc] initWithImage:image]

As mentioned by Clayton and Aaron Brager, the key is imageWithCGImage method of UIImage class.
There are a two ways to get image content:
asset.thumbnail or asset.aspectThumbnail
via a presentation of the asset
there are default presentation and presentation for UTI
CGImage prepared
CGImageWithOptions, fullResolutionImage, fullScreenImage
raw data
getBytes:fromOffset:length:error:
(if you want to keep EXIF etc, use imageWithData instead of imageWithCGImage)
You may refer http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAssetRepresentation_Class/Reference/Reference.html#//apple_ref/doc/c_ref/ALAssetRepresentation for more details.

ALAssetRepresentation *rep = [self defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[rep fullScreenImage]];

Related

Take a snapshot of a PKAddPassesViewController's view

I'm trying to take a snapshot of the view displayed when the user is prompted to add a pass.
The goal is being able to generate an image from a given pkpass
I was hoping something like this could work:
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"columbus" ofType:#"pkpass"];
PKPass *pass = [[PKPass alloc] initWithData:[NSData dataWithContentsOfFile:filePath] error:nil];
PKAddPassesViewController *pkAddPassesViewController = [[PKAddPassesViewController alloc] initWithPass:pass];
[self presentViewController:pkAddPassesViewController animated:YES completion:^(){
UIImage *image = [pkAddPassesViewController.view captureView];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.view addSubview:imageView];
}];
With captureView being:
- (UIImage *)captureView
{
CGRect screenRect = self.bounds;
UIGraphicsBeginImageContext(self.bounds.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor clearColor] set];
CGContextFillRect(ctx, screenRect);
[self.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Guess what? I was wrong:
I tried:
Using the completion callback and the animationFinished callback
Setting the hidden property
Using a timer to make sure the pass was visible on screen when the screenshot was taken
Taking a snapshot of the parent view
I ran out of ideas, so any suggestion is appreciated
Thanks in advance
Oh, I've uploaded a minimal project here:
https://github.com/framp/demo-capturing-passbook
EDIT:
I'm able to take a snapshot of other views and I can load other UIImage just fine with the code above.
The UIImage which is returned is a blank image
Try this, this might work for you.
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData=UIImagePNGRepresentation(reportImage);
The capture image code is good. Try with : [self.view.superview addSubview:imageView]; in the completion block instead of [self.view addSubview:imageView];
You can try this code if that work for you. Give the Coordinates which you want to capture and thats it. It will save your file in image album. It may give a warning but it works.
UIGraphicsBeginImageContext(CGSizeMake(320, 380));
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
I think pkAddPassesViewController is not fully loaded when you taken snapshot. So my suggestion is to take screenshot after some delay.
I hope it will work.

Applying CIFilter to UIImageView

In UIViewController displaying image in UIImageView. I want to display it with some special effects. Using core image.framework
UIImageView *myImage = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:#"piano.png"]];
myImage.frame = CGRectMake(10, 50, 300, 360);
CIContext *context = [CIContext contextWithOptions:nil];
CIFilter *filter= [CIFilter filterWithName:#"CIVignette"];
CIImage *inputImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:#"piano.png"]];
[filter setValue:inputImage forKey:#"inputImage"];
[filter setValue:[NSNumber numberWithFloat:18] forKey:#"inputIntensity"];
[filter setValue:[NSNumber numberWithFloat:0] forKey:#"inputRadius"];
[baseView addSubview:inputImage];
but looks like I'm missing something or doing something wrong.
As the other post indicates, a CIImage is not a view so it can't be added as one. CIImage is really only used for doing image processing, to display the filtered image you'll need to convert it back to a UIImage. To do this, you need to get the output CIImage from the filter (not the input image). If you have multiple filters chained, use the last filter in the chain. Then you'll need to convert the output CIImage to a CGImage, and from there to a UIImage. This code accomplishes these things:
CIImage *result = [filter valueForKey:kCIOutputImageKey]; //Get the processed image from the filter
CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]; //Create a CGImage from the output CIImage
UIImage* outputImage = [UIImage imageWithCGImage:cgImage]; // Create a UIImage from the CGImage
Also remember that the UIImage will have to go into a UIImageView, as it's not a view itself!
For more information, see the Core Image programming guide: https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/CoreImaging/ci_intro/ci_intro.html
CIImage can not be added as subview because it is not a view (UIView subclass). You need a UIImageView with a UIImage attached to its 'image' property (and this UIImage you can create from the CIImage, I believe).

Loading gif image in UIWebview - iPhone

When Iam loading a gif image in UIWebview in the iPhone 4.3 simulator it is getting an error like
ImageIO: <ERROR> _CGImagePluginInitGIFmalformed GIF frame#0 (640 x 960)
And the gif image is not showing. Can anyone help me...
Now in iPhone, Apple not supported .gif images.
You can use other type of images like png, jpg..
If you have a serie of images you want to animate you can easily do it with UIImageView:
UIImage *image1 = [UIImage imageNamed:#"image1.png"];
UIImage *image2 = [UIImage imageNamed:#"image2.png"];
UIImage *image3 = [UIImage imageNamed:#"image3.png"];
self.imageView.animationImages = [[NSArray alloc] initWithObjects:image1,image2,image3, nil];
self.imageView.animationRepeatCount = 7;
[self.imageView startAnimating];

Low Clarity with ALAsset Thumbnail

I am binding the photo Library images to my Table-view using ALAsset Library.
So whenever i am binding the ALAsset Thumbnail image as a TableView cell image, there is a issue with image Clarity.It Shows as a low clarity image.
I have Created a full resolution image from AlAsset and wrote the thumbnail generation method, i have set the resultant image as table-view image.
After done the above process, i got the full resolution image thumbnail on Table-view.
But the issue was the performance with first time table View image bind process(i used a cache to bind the image after bind first time.So the performance will fast after first time).
So May i know, How can i get the Photo-library full clarity thumbnail image from ALAsset?
I have wrote the below code in MyTableView CellForRowIndexPath is
UIImageView *importMediaSaveImage=[[[UIImageView alloc] init] autorelease];
importMediaSaveImage.frame=CGRectMake(0, 0, 200,135 );
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
CGImageRef iref = [myasset thumbnail];
if (iref) {
importMediaSaveImage.image = [UIImage imageWithCGImage:iref];
}
etc...
I have tried the below method which is time consuming
UIImageView *importMediaSaveImage=[[[UIImageView alloc] init] autorelease];
importMediaSaveImage.frame=CGRectMake(0, 0, 200,135 );
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
UIImage *images;
if (iref) {
images = [UIImage imageWithCGImage:iref];
}
NSData *data = [self photolibImageThumbNailData:images];
importMediaSaveImage.image = [UIImage imageWithData:data];
etc....
photolibImageThumbNailData
-(NSData *)photolibImageThumbNailData:(UIImage *)image{
// begin an image context that will essentially "hold" our new image
UIGraphicsBeginImageContext(CGSizeMake(200.0,135.0));
// now redraw our image in a smaller rectangle.
[image drawInRect:CGRectMake(0.0, 0.0, 200.0, 135.0)];
// make a "copy" of the image from the current context
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// now grab the PNG representation of our image
NSData *thumbData = UIImagePNGRepresentation(newImage);
return thumbData;
}
Thanks.
i don't think there is much you can do here.. as those are the only two options we have from ALAsset. you will have to compromise either on quality or time. If you are using the images that you have yourself stored in the library then you can re size them before storing to be a bit smaller to increase the speed of the process.
You should also try [rep fullScreenImage] for a better performant table view but an image with better quality than thumbnail.
You can use
CGImageRef iref = [myasset aspectRatioThumbnail];
and your thumbnail look much better !

What software is used to animate and create the Cat in Talking Tom application in iphone

I was curious to know what software is used to create the 3D Cat in the talking tom app in iphone. Is it done with OpenGL ES?
http://itunes.apple.com/us/app/talking-tom-cat/id377194688?mt=8
Well if it's related to talking tom then there is no OpenGL ES use... they are simply using images and animating them, something like this:
aniImage = [[UIImageView alloc] init];
UIImage* opa1 = [UIImage imageNamed:#"o1.png"];
UIImage* opa2 = [UIImage imageNamed:#"o2.png"];
UIImage* opa3 = [UIImage imageNamed:#"o3.png"];
UIImage* opa4 = [UIImage imageNamed:#"o4.png"];
UIImage* opa5 = [UIImage imageNamed:#"o5.png"];
UIImage* opa6 = [UIImage imageNamed:#"o6.png"];
UIImage* opa7 = [UIImage imageNamed:#"o7.png"];
UIImage* opa8 = [UIImage imageNamed:#"o8.png"];
UIImage* opa9 = [UIImage imageNamed:#"o9.png"];
UIImage* opa10 = [UIImage imageNamed:#"o10.png"];
UIImage* opa11 = [UIImage imageNamed:#"o11.png"];
UIImage* opa12 = [UIImage imageNamed:#"o12.png"];
UIImage* opa13 = [UIImage imageNamed:#"o13.png"];
UIImage* opa14 = [UIImage imageNamed:#"o14.png"];
UIImage* opa15 = [UIImage imageNamed:#"o15.png"];
UIImage* opa16 = [UIImage imageNamed:#"o16.png"];
UIImage* opa17 = [UIImage imageNamed:#"o17.png"];
UIImage* opa18 = [UIImage imageNamed:#"o18.png"];
NSArray *imgsArr = [NSArray arrayWithObjects:opa1, opa2, opa3, opa4,
opa5, opa6, opa7, opa8, opa9, opa10, opa11, opa12, opa13, opa14, opa15, opa16, opa17, opa18, nil];
[aniImage setAnimationImages:imagesOpacity];
[aniImage setAnimationRepeatCount:1.0];
[aniImage setAnimationDuration:0.2];
If you want to see all the images they are using follow these steps:
Download the free version to your iPhone/iPad.
Transfer your purchases on your Mac or Windows computer.
Then drag the ipa file from Library -> Apps to your desktop (just drag the app icon from iTunes to desktop).
Rename the .ipa file to .zip file.
Extract this zip file. You will get a folder named "Payload" in it.
Open the .app file (it will open on Windows automatically because it is a folder on Windows,
on Mac right click on it and select Show package content.
In the .app folder you will find a folder which contains all the images used by the above function.
Hope this helps.
Go for OpenGLES
Video Tutorials: http://vimeo.com/6381001
Blog Post : http://www.71squared.com/2009/03/iphone-game-programming-tutorial-1/