开发者

Animated-GIF images received as NSData through NSSocket unable to split frames

I'm having trouble with the way iOS handles animated-GIF's. I know that you cannot use animated-GIF's on an UIImageView and you have to use custom animations on the UIImageView.

But..

I have a Java server that sends GIF images through a socketstream. The iOS (iPhone) receives that stream and converts it into an NSData type. I've succeeded in capturing and displaying this image in a UIImageView but as many of you already know.. it only displays the first frame.

I Also found some code to decode that GIF into separate images, but that code works from a GIF file and not NSData.

Question: How do i convert the NSData file into separate images and place them in an NSArray to use it as animation?

Note: In the NSData that is received are both an image and some text separated by a rare character. so the NSData looks like开发者_开发技巧 this: [image] [separator] [text].

Hope somebody can give me some pointers or some samples to work with..

Thanks in advance, i will keep searching untill you or me finds an answer :)


Unless you're targeting devices before IOS 4, use ImageIO.

NSMutableArray *frames = nil;
CGImageSourceRef src = CGImageSourceCreateWithData((CFDataRef)data, NULL);
if (src) {
    size_t l = CGImageSourceGetCount(src);
    frames = [NSMutableArray arrayWithCapacity:l];
    for (size_t i = 0; i < l; i++) {
        CGImageRef img = CGImageSourceCreateImageAtIndex(src, i, NULL);
        if (img) {
            [frames addObject:[UIImage imageWithCGImage:img]];
            CGImageRelease(img);
        }   
    }   
    CFRelease(src);
}


I made a wrapper that also handles animation time based on the code from Anomie

https://gist.github.com/3894888

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜