GIF Support for Iphone - iphone

My Sires, My Dames (ah.. just another knightly thing,...)
I have a question, I have been battling with this for days, here's my scenario:
I have an HTTP response which contains a link to a GIF Image, the GIF image then is converted into an NSData, and later on used to populate an ImageView. Expectedly or Unexpectedly, only the first frame/transition of the GIF is shown. Simply said, the image loads but doesn't animate.
What I want to know if there is native support for GIF in iPhone, likewise I found an extended class here SCGifExample
which seems to appear to work only when I import the GIF image within the app, but not when the image is coming from a URI->NSData.
I don't want to create multiple images then create an array of images because that is not gonna work my setup as it will give a lot of load to the server and the client.
I've made my search here at SO, but I didn't found any substantial result to stop me from posting my own question as a matter of fact I found many questions here related to iphone+gif are left unanswered.
I do have a suspicion, and I was hoping somebody could help me figure out and understand it. I suspect that the GIF Animation/Transition is "LOST" during the conversion from Image to NSDATA format. But I don't have any concrete evidence to back this up tho.
Here's how I convert the image into NSData;
contentURI = http://gta.champion.com/content?cmsFileId=513af9e9-a96d-4a56-8239-92be273393e0&mt=image/gif //lets just assume that when view using the browser, this would display the image.
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: contentURI]];
If there was somebody else who came victor of this plight, please help me to conquer such feat also.

Yes there is an alternate , but it depends on the case you have.But let me share the idea with you because using the UIWebView solved my problem since I just need to Animate a single image i.e Advertisement.
Here is the code Snippet :
UIWebView *webV = [[[UIWebView alloc]initWithFrame:appDel.isiPad==TRUE?CGRectMake(260, 35, 500, 100):CGRectMake(40, 18, 250, 60)] autorelease] ;
webV.delegate =self;
webV.multipleTouchEnabled=NO;
[webV setBackgroundColor:[UIColor whiteColor]];
webV.userInteractionEnabled=NO;
[webV loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"YourImageUrl"]]];
And implement their delegate methods :
- (void)webViewDidStartLoad:(UIWebView *)webView;
- (void)webViewDidFinishLoad:(UIWebView *)webView;
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;

While Apple's APIs do not support animated GIFs out-of-the-box, there is a user-created solution that is just as effective:
LBGIFImage:
https://github.com/larcus94/LBGIFImage

Unfortunately iOS does not support GIF images, also you cannot use them for animations. If you use GIF images, the imageview will show the first frame of that image, nothing more.
Please refer UIImage for the supported formats.

See what I found out about showing animated gif in iOS. http://iosnotestoremember.blogspot.com/2013/01/showing-animated-gif-in-ios.html
I hope this helps.

Related

ScrollView with over 150 images crashes

I've an application which is a scrollView filled with over 150 images .. I've followed this tutorial to create it .. the application is over 550MBs and it has about 500 (150 for iPhone 5 & 150 for Retina & 150 for non-retina & buttons) photos .. The application runs very well on the simulator with no problems but on a real device when I open the application it keeps loading then a crash
so can anyone help me with this, please?
Thanks in advance.
Try to load only those images needed for displaying. ie while scrolling those images that are hidden should be taken off from the scrollview. Maybe you can make a design similar to the working of reusable UITableViewCell. ie a custom implementation for showing only the needed images and reusing them while scrolling.
There is another way, not a straight forward one, you can use a UITableView and add images to each cell and then rotate the tableview so that it will look like an horizontal scroll.
The advantage of doing this method is that the UITableView will handle all the reusability issue and we dont need to worry about. But I am not sure whether its the right way to do this.
Btw.. I have uploaded an app with the UITableView rotated horizontal scroll view to the appstore without getting rejected ;)
It is not an good way to do that ,u can upload your photo on server side and when open the app. loading the image from server.
id path = #"http://upload.wikimedia.org/wikipedia/commons/c/c7/Sholay-Main_Male_Cast.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
imageView.image = img;
LooK at this answer

TTPhotoViewController: deactivate gallery auto zoom

In my project, I use the Facebook API "three20": https://github.com/facebook/three20/
Now, I need to customize the TTPhotoViewController.
In the gallery, there's an "auto zoom". The complete width and height are always used:
The disadvantage is that you can not see the complete photo and important information could be cut off / cropped.
How can I deactivate the automatic zoom?
Thanks!
EDIT 03-Mar-2011:
Roman's answer seems to be good, but unfortunately it doesn't helps me. Yes, the content mode UIViewContentModeScaleAspectFill is the problem:
Scales the content to fill the size of
the view. Some portion of the content
may be clipped to fill the view’s
bounds.
But there's no other content mode that solves my problem. I think, I have to look deep inside three20 and scale the images by myself. But I need your help to do this! So, I'll start a new "bounty" today (03/03/2011)...
Thank you very much!!
EDIT 07-Mar-2011:
Finally I got it!! roman's answer is right, I have to use UIViewContentModeScaleAspectFit.
The problem was: I use a wrong size in my Photo-Object! 320x480 worked for me:
NSMutableArray *photos = [NSMutableArray new];
for (Information *info in allImages) {
NSString *binaryId = info.binary;
NSString *fileName = [NSString stringWithFormat:#"documents://img/%#.jpg", binaryId];
Photo *photo = [[[Photo alloc] initWithCaption:info.name
urlLarge:fileName
urlSmall:fileName
urlThumb:fileName
size:CGSizeMake(320, 480)] autorelease];
[photos addObject:photo];
}
self.photoSource = [[PhotoSet alloc] initWithTitle:#"Photos" photos:photos];
easiest way is to hack TTPhotoView - around line 135 (function setImage) change
self.contentMode = UIViewContentModeScaleAspectFill;
to
self.contentMode = UIViewContentModeScaleAspectFit;
sadly there does not seem to be another way currently.
You should award your question to roman because he answers your specific question, but I want to suggest that you should consider not using three20 and implement your image scroller yourself. Take a look at Session 104, Designing Apps with Scroll Views (requires ADC login) from the WWDC 2010 session videos on iTunes. It walks you through exactly how to implement this type of interface and allows you to keep your app lean without having to add the entire three20 library to your code.
Make this change in TTScrollView class
In the method
- (CGRect)frameOfPageAtIndex:(NSInteger)pageIndex
In this method, change the following line
if (size.width > size.height) {
to
if (size.width / size.height > self.width / self.height) {
This worked for me.

Memory Management

I need a clarification from all of you,That is I am implementing an iPad application. In that I tried to download and animate the images. The image count should be more than 100,000.The code I used to download and adding to the view is as follows.
UIImageView* imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,100,100)];
NSData *receivedData=nil;
receivedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://path/prudently/iphone/image_s/e545afbf-4e3e-442e-92f9-a7891fc3ea9f/test.png"]];
imageView.image = [[UIImage alloc] initWithData:receivedData] ;
[subView addSubview:imageView];
[imageView release];
But I am getting exception after I successfully added more than 8000 image to my subview. I am getting exception at getting data from the url. And one more thing I am not releasing the subview because once I downloaded them I need to animate the subview.
Please give me your suggessions
Thank you,
Sekhar Bethalam.
100,000 images would seem a lot for desktop applications, let alone a smart phone like an iPhone. Is there not another approach you can take to solve this problem that wouldn't need such a high resource count?
You can write the URL , images or something to a cached file, and divide some pages to animate the images...
When the user press a page link , application read and animate the images of this page, images of the page which user don't use need not display.
The only way you are going to accomplish this is to dynamically create and destroy the UIImageViews as they are needed on the screen. The iPhone/iPad/iAnything are incapable of doing what you want because of the limited memory available on the device.

UIImage View + Pinch/Zoom feature when image is downloaded from web

I have a UIImageView, which pics up different images from the web, they are all different res. I have them to display as Aspect fit so that the whole picture displays even if it means leaving empty space on top or sides.
What i want to have the feature of doing is, once its displayed, to zoom in and out using the pinch or any other way.
NSURL* iURL = [NSURL URLWithString:tURL];
NSData* iData = [NSData dataWithContentsOfURL:iURL];
UIImage* iImage;
iImage = [UIImage imageWithData:iData];
FullScreenImage.image = iImage;
All this code is being executed on another thread, then it returns to the main thread and is displayed on a view using
[navigationController pushViewController:vFullscreen animated:YES];
Thanks for the help
You will need to use a UIScrollView as UIImageView does not offer any built-in zooming. See the Apple example entitled: ScrollViewSuite

Why can't I capture a screenshot of MPMoviePlayerController?

I need to capture a screen shot of a video playing in mpmovieplayer controller, but all I get is a red screen (I made the coverView with red background and 0.5 alpha).
Here is the code:
NSArray *windows = [[UIApplication sharedApplication] windows];
if ([windows count] > 1)
{
UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
UIView *coverView = [[UIView alloc] initWithFrame:moviePlayerWindow.bounds];
[mainController.moviePlayer pause]; //Without that it won't work either!
coverView.backgroundColor = [UIColor redColor];
coverView.alpha = 0.5;
[moviePlayerWindow addSubview:coverView];
UIGraphicsBeginImageContext(coverView.bounds.size);
[coverView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenShot;
screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(screenShot, self, nil, nil);
}
Any ideas???
Thanks
I was curious about his myself. I believe there are similar issues with taking screenshots of OpenGL stuff too.
If you look at this blog post http://getsetgames.com/2009/07/30/5-ways-to-take-screenshots-of-your-iphone-app/, they have a method that works for an EAGLView, it might be worth giving it a go for your issue.
Follow up to the question:
Recently I have a project that requires the functionality that was asked in this thread again, and I am glad to say there is already an apple provided solution to this. I am posting this so that people that visit this thread can get an answer.
MPMoviePlayerController now has a method that return a UIImage of the moment you want to capture.
- (UIImage *)thumbnailImageAtTime:(NSTimeInterval)playbackTime timeOption:(MPMovieTimeOption)option
Just put in the playbackTime you want to capture, and bingo, UIImage.
Looking at your codes, I would like to advise that you should look for an alternative method of getting the image rather than from the mpmovieplayer itself. The reason being that the method you are using is a private framework code, and second, getting screenshots off a video is highly prone to crashes.
Instead of getting a screenshot from the video, how about tagging the video beforehand? The codes looks highly vulnerable to an app rejection by apple.
Sounds like you're taking a shot of the video overlay mask
http://en.wikipedia.org/wiki/Hardware_overlay