12

I'm probably going to get flamed for this.

I am wondering if anyone know of any way to load APNG (animated PNG) inside an iPhone app?

I'm not talking about multiple PNG image added as an NSArray of UIImages to a UIImageView. I already can do this method but this requires multiple PNG images.

I'm talking about a special PNG format called APNG (http://en.wikipedia.org/wiki/APNG) that only contains 1 PNG file but has animation meta data.

I've found this library called AVAnimator: http://www.modejong.com/AVAnimator/index.html which supposedly can load APNG format but the licence cost $475 USD and the library appears to be from a few years ago (iOS 4).

I also read that Apple iOS 8 Safari as well as Yosemite Safari has built in support for APNG.

I really don't want to resort to using a UIWebView just to display an APNG file. It works, I've tested it but I don't think that's ideal.

I was hoping there is some undiscovered new iOS SDK that lets us load APNG into the app that I'm not aware of and maybe you guys might know.

How does the Line app (http://line.me/en/) do it ? They seem to have animated PNGs for their "stickers".

Zhang
  • 11,253
  • 6
  • 51
  • 80
  • 1
    i didnt use apng but if requirement isnt that strict i would go for gifs and use https://github.com/Flipboard/FLAnimatedImage – turbo Apr 24 '15 at 15:37
  • @turbo I came across that library too, it currently supports GIF but one of the to-do item is to add APNG and WebP support. Fingers crossed :) – Zhang Apr 26 '15 at 16:46
  • 1
    See https://stackoverflow.com/questions/25074340/avanimator-mvid-conversion/25478854#25478854 for a complete solution – MoDJ Jun 05 '15 at 23:13
  • Not supported natively yet on iOS, but you can use a third-party like https://github.com/onevcat/APNGKit or https://github.com/ibireme/YYImage. – Cœur Sep 05 '19 at 07:16

3 Answers3

6

I just released a framework to load and display APNG files for iOS.

You could just load an APNG image with the same pattern of UIImage and UIImageView like this by using it:

let image = APNGImage(name: "your_apng_image")
let imageView = APNGImageView(image: image)

imageView.startAnimating()

view.addSubview(imageView)

For more information, you can find it here: https://github.com/onevcat/APNGKit

onevcat
  • 4,421
  • 1
  • 19
  • 29
  • 1
    Just linking to your own library is not a good answer. Linking to it, explaining why it solves the problem, providing code using the library to do so and disclaiming that you wrote it makes for a better answer. See: [**What signifies “Good” self promotion?**](http://meta.stackexchange.com/q/182212/200235) – durron597 Sep 03 '15 at 14:02
  • Do you have any idea for Objective C – Nam Vu Mar 04 '16 at 02:45
  • I need to use the library ASAP, could you, please, convert it to Swift 3. I managed to save an animation into APNG format using ImageIO, but need your library to load it into an array of UIImage. https://github.com/radif/MSSticker-Images/blob/master/Classes/mcbAnimatedImagePersister.m – Radif Sharafullin Aug 16 '16 at 17:05
  • Your APNGKit looks nice. Sorry for the late reply, I'll test this solution when I get home tonight. – Zhang Mar 29 '17 at 02:46
  • 1
    Holy smokes, it works o.O Only problem is when I autolayout the imageView, it seems I need to specify a width and height, otherwise the imageView doesn't appear if I just tell it to centerX/Y to viewController's view centerX/Y. Thanks heaps for making this library :D – Zhang Mar 29 '17 at 15:14
  • @onevcat It's lagging in my case. Can you suggest any hack? I've XR as a real device. Device is cool and free in memory. – Chetan Prajapati May 11 '21 at 13:20
3

It's really undocumented, but it's somewhere in ImageIO framework.

I can see some APNG strings in CGImageProperties.h

maxst
  • 228
  • 1
  • 1
  • No, ImageIO does not support APNG. It does support animated GIF but not APNG. – MoDJ Jun 05 '15 at 23:12
  • 3
    I managed to save an animation into APNG format using ImageIO, but not sure how to load it into an array of UIImage https://github.com/radif/MSSticker-Images/blob/master/Classes/mcbAnimatedImagePersister.m – Radif Sharafullin Aug 16 '16 at 17:03
  • We warned these can't be saved to the photo library – jjxtra Aug 17 '16 at 01:30
3

I found this code,

https://github.com/radif/MSSticker-Images/

you can create a MSSticker APNG with multiply PNG. Maybe you can extract a part of this.

Carolina
  • 417
  • 3
  • 18
  • How about if i have to download APNG from server and then load into stickerview ? that example only showing to make sticker with apng or png – Shauket Sheikh Dec 07 '17 at 15:22