How to split gif-animated images in iOS

I don't understand how to share .gif animated images using UIActivityViewController.please help me solve this.thanks in advance

see this image .i am displaying this type of images and to share these images I am using uiactivity view but it is not animating .it just displaying image if(imgFrameCount==1) { imgFrameCount++; NSURL *url1=[[NSBundle mainBundle]URLForResource:@"animated2" withExtension:@"gif"]; self.firstImage=[UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url1]]; self.frameImage.image = self.firstImage; } else if (imgFrameCount==2) { imgFrameCount++; NSURL *url2=[[NSBundle mainBundle]URLForResource:@"animated3" withExtension:@"gif"]; self.firstImage=[UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url2]]; self.frameImage.image = self.firstImage; } 
+1
source share
4 answers

FWIW, I had the same problem when trying to include UIImage in an array of ActivityItems. It will not work with generic UIImage or UIImage using the categories UIImage + animagedGIF or FLAnimatedImage.

To solve this problem, at least on iOS8, just add the gif to the ActivityItems array as an NSData object, not a UIImage.

For example, if a gif is requested from a URL:

 NSURL *imagePath = [NSURL URLWithString:@"http://i.imgur.com/X4oonnm.gif"]; NSData *animatedGif = [NSData dataWithContentsOfURL:imagePath]; NSArray *sharingItems = [NSArray arrayWithObjects: animatedGif, nil]; UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil]; 
+6
source

This is a difficult problem because different sharing receivers process data differently. Therefore, the NSData solution mentioned in other answers works when used together in several different applications, but not for most of them. It seems that the receiver should be smart enough to decode an array of bytes and determine that it is really an animated gif, but most of them do not. It’s better to plan to send a link to a file with the appropriate extension, since most applications recognize the file extension. Therefore, my current strategy is taken from fooobar.com/questions/350866 / ... , but is written to a file called "share.gif" or similar. With the sharing of almost all applications that can handle animated gifs, it is possible to get it correctly.

+2
source

Try using this code.

 NSArray *animeImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"tmp-0.png"], [UIImage imageNamed:@"tmp-1.png"], [UIImage imageNamed:@"tmp-2.png"], [UIImage imageNamed:@"tmp-3.png"], [UIImage imageNamed:@"tmp-4.png"], [UIImage imageNamed:@"tmp-5.png"], [UIImage imageNamed:@"tmp-6.png"], [UIImage imageNamed:@"tmp-7.png"], [UIImage imageNamed:@"tmp-8.png"], [UIImage imageNamed:@"tmp-9.png"], [UIImage imageNamed:@"tmp-10.png"], [UIImage imageNamed:@"tmp-11.png"], nil]; imageView.image = [UIImage animatedImageWithImages:animeImages duration:2.0]; 

Now you can play with this image and set its various properties, such as frame and hidden, etc., to make it work as an indicator of activity. The images transferred in the array are a breakdown of the animated gif. This can be easily done with any online tool like this .

+1
source

That should do it. Extension of Jordan Bonitatis response. The trick is to create an NSData object with NSURL content.

 - (void)share { NSURL *imageURL = [NSURL URLWithString:@"http://...url..of..gif]; NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; NSArray *objectsToShare = @[imageData]; UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; NSArray *excludeActivities = @[UIActivityTypeAirDrop, UIActivityTypePrint, UIActivityTypePostToVimeo]; activityVC.excludedActivityTypes = excludeActivities; [self presentViewController:activityVC animated:YES completion:nil]; } 
0
source

All Articles