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];
Related
Iam developing one application.In that i want to set the uiview background as image.That image size is 1.6 mb.I followed the below code.
UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:#"image.png"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
But it takes more time compared to small size image.So please help me how to load 3mb size of image also like as small size of image.
You could do the drawing operations on a background queue, so it won't freeze the UI:
CGRect imgRect = self.view.bounds;
dispatch_async(dispatch_get_global_queue(0, 0), ^{
UIGraphicsBeginImageContext(imgRect.size);
[[UIImage imageNamed:#"image.png"] drawInRect:imgRect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIColor* bgcolor = [UIColor colorWithPatternImage:image];
dispatch_async(dispatch_get_main_queue(), ^{
self.view.backgroundColor = bgcolor;
});
});
Also optimize the image by using the tool ImageOptim.
Its best if you resize image and then add in Application bundle to execute faster.
here I think there is no need get image firstly for resizing for UIView s pattern image in background.
You can solve memory issue like this:
NSString *imgfile = [[NSBundle mainBundle] pathForResource:#"image" ofType:#"png"];
UIImage *currentImage = [UIImage imageWithContentsOfFile:imgfile];
self.view.backgroundColor = [UIColor colorWithPatternImage:currentImage];
Refer ios-imagenamed-vs-imagewithcontentsoffile link.
EDIT : Use #phix23 answer for smooth UI
I created an animated image, and it animates properly in an UIImageView:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *image1 = [UIImage imageNamed:#"apress_logo"];
UIImage *image2 = [UIImage imageNamed:#"Icon"];
UIImage *animationImage = [UIImage animatedImageWithImages:[NSArray arrayWithObjects:image1, image2, nil] duration:0.5];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
imageView.image = animationImage;
[self.view addSubview:imageView];
}
But if saved to photos album, it couldn't animate agian:
UIImageWriteToSavedPhotosAlbum(animationImage,
self,
#selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:),
nil);
So is there any solution to save an animated image to photos album?
Special thanks!
The photo album is an application as well, like exactly what you are making. Except to animate an image you wrote corresponding code like,
UIImage *animationImage = [UIImage animatedImageWithImages:[NSArray arrayWithObjects:image1, image2, nil] duration:0.5];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
imageView.image = animationImage;
But you assumed that your Image will be treated in similar way inside your photo album app as well. Then No thats not true. in photo album app probably the application just reading an Image from disk and then shows in inside UIImageView without any animation "BECAUSE THERE IS NO ANIMATION CODE" :)
This creates an opportunity to create a photo album with animated images.
I have seen programs like Quartz Composer creating .mov file from several images and creating animations to it. But thats professionally built by Apple. Now, I said because I think it's possible to create .mov by using API but you might have to dig deeper as I have no idea how to.
The closest reference I can find is this :
http://www.cimgf.com/2008/09/10/core-animation-tutorial-rendering-quicktime-movies-in-a-caopengllayer/
I am developing an iPhone app in which I am capturing the live video.
I have added the AVCaptureVideoPreviewLayer to the self.view.layer as sublayer.
[self.view.layer addSublayer: self.prevLayer];
On the same self.view I have added an image as subview.
[self.view addSubView:image];
Now what I want is to capture an image from the live video but the image should also come into that picture as it looks on the screen.
I have tried to take the screen shot but it capture only the image and not the live video image.
Can any body please help me on this.
Thanks in advance.
hi this will help you as it works for me
- (void)didTakePicture:(UIImage *)picture
{
UIImage *frm = self.overlayViewController.imgOverlay.image;
NSLog(#"width %f height %f",picture.size.width,picture.size.height);
UIGraphicsBeginImageContext(picture.size);
[picture drawAtPoint:CGPointMake(0,0)];
[frm drawInRect:CGRectMake(0, 0, picture.size.width, picture.size.height)];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(#"view %#",viewImage.debugDescription);
[self.capturedImages addObject:viewImage];
}
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]];
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/