GIF Support

Is it possible to have an array of iOSImages from a gif (in iOS)?

Apparently, adding images to iOSImage array works fine, both adding iOSImages or iOSBitmap.Image. myImage is a Gif picture I dragged into the project.

[code] dim myBitmap as new iOSBitmap(myImage.width,myImage.height, 1)
myBitmap.Graphics.DrawImage(myImage,0,0)

dim images() as iOSImage
images.Append(myImage)
images.Append(myBitmap.Image)
me.Image = images(1)[/code]

If you extract all of the frames from the gif in Preview you can load them with a declare (untested):

declare function animatedImageNamed_ lib "UIKit" selector "animatedImageNamed:duration:" (clsRef as ptr, name as CFStringRef, duration as Double) as ptr declare function NSClassFromString lib "Foundation" (clsName as CFStringRef) as ptr dim frameDuration as double = 1.0 //each frame will last 1 second dim img as iOSImage = iOSImage.FromHandle(animatedImageNamed_(NSClassFromString("UIImage"), "mygif", frameDuration))
Then you just have to name each frame mygif0, mygif1, mygif2, etc. and they will be automatically loaded as an animated image from your app resources. Full explanation of the function is here:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/index.html#//apple_ref/occ/clm/UIImage/animatedImageNamed:duration:
Hopefully this helps,
Jason

[quote=202909:@Jason King]If you extract all of the frames from the gif in Preview you can load them with a declare (untested):

declare function animatedImageNamed_ lib "UIKit" selector "animatedImageNamed:duration:" (clsRef as ptr, name as CFStringRef, duration as Double) as ptr declare function NSClassFromString lib "Foundation" (clsName as CFStringRef) as ptr dim frameDuration as double = 1.0 //each frame will last 1 second dim img as iOSImage = iOSImage.FromHandle(animatedImageNamed_(NSClassFromString("UIImage"), "mygif", frameDuration))
Then you just have to name each frame mygif0, mygif1, mygif2, etc. and they will be automatically loaded as an animated image from your app resources. Full explanation of the function is here:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/index.html#//apple_ref/occ/clm/UIImage/animatedImageNamed:duration:
Hopefully this helps,
Jason[/quote]

I did not get the animated gif possibility. The simplest way to display one, though, is to show it into an HTMLViewer.

Probably true, however then you can’t have the autoscaling and other benefits of using an image view. It depends on what his needs are.

Indeed.

Thank you very much! In order to get an animation I have to calculate the time between one frame and the following, how can I obtain this time?

You set the time if you modify the constructor and pass a duration value as double too which you use instead of the frameduration property in Jason’s example.

You read it (it’s read-only and can only be defined in the constructor) by

Declare Function duration lib "UIKit" selector "duration" (id as ptr) as Double Return duration (img.handle)

Thank you very much! Xojo forums are the best out there.

In case you need more UIImage features, feel free to rip the code from https://github.com/UBogun/Xojo-iosLib/wiki/AppleImage