APNG inside iOS app
Asked Answered
V

3

14

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".

Victoir answered 24/4, 2015 at 10:18 Comment(4)
i didnt use apng but if requirement isnt that strict i would go for gifs and use github.com/Flipboard/FLAnimatedImageEldreeda
@Eldreeda 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 :)Victoir
See https://mcmap.net/q/831246/-avanimator-mvid-conversion/… for a complete solutionNeurath
Not supported natively yet on iOS, but you can use a third-party like github.com/onevcat/APNGKit or github.com/ibireme/YYImage.Willie
D
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

Dramatics answered 3/9, 2015 at 12:3 Comment(6)
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?Xerophyte
Do you have any idea for Objective CNascent
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. github.com/radif/MSSticker-Images/blob/master/Classes/…Geraint
Your APNGKit looks nice. Sorry for the late reply, I'll test this solution when I get home tonight.Victoir
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 :DVictoir
@Dramatics 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.Atonsah
D
3

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

I can see some APNG strings in CGImageProperties.h

Daw answered 24/4, 2015 at 15:32 Comment(3)
No, ImageIO does not support APNG. It does support animated GIF but not APNG.Neurath
I managed to save an animation into APNG format using ImageIO, but not sure how to load it into an array of UIImage github.com/radif/MSSticker-Images/blob/master/Classes/…Geraint
We warned these can't be saved to the photo libraryMinicam
L
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.

Lingam answered 20/7, 2016 at 15:46 Comment(1)
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 pngBonnee

© 2022 - 2024 — McMap. All rights reserved.