[Library] AnimatedGifEncoder!

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hey!

Create your own animated gif files with this library.
The code is easy to use and to understand.
The library files and sample are delivered in the attachments.

  • RSAnimatedGifEncoder
    Properties:
    • Delay As
      Sets the delay time between each frame, or changes it for subsequent frames
      (applies to last frame added).
    • Dispose As
      Sets the GIF frame disposal code for the last added frame and any
      subsequent frames. Default is 0 if no transparent color has been set,
      otherwise 2.
    • FrameRate As
      Sets frame rate in frames per second. Equivalent to
      <code>setDelay(1000/fps)</code>.
    • Quality As
      Sets quality of color quantization (conversion of images to the maximum 256
      colors allowed by the GIF specification). Lower values (minimum = 1)
      produce better colors, but slow processing significantly. 10 is the
      default, and produces good color mapping at reasonable speeds. Values
      greater than 20 do not yield significant improvements in speed.
    • Repeat As
      Sets the number of times the set of GIF frames should be played. Default is
      1; 0 means play indefinitely. Must be invoked before the first image is
      added.
    • Transparent As
      Sets the transparent color for the last added frame and any subsequent
      frames. Since all colors are subject to modification in the quantization
      process, the color in the final palette for each frame closest to the given
      color becomes the transparent color for that frame. May be set to null to
      indicate no transparent color.
    Methods:
    • addFrame (im As Bitmap) As Boolean
      Adds next GIF frame. The frame is not written immediately, but is actually
      deferred until the next frame is received so that timing data can be
      inserted. Invoking <code>finish()</code> flushes all frames. If
      <code>setSize</code> was not invoked, the size of the first image is used
      for all subsequent frames.
      im: BufferedImage containing frame to write.
      Return type: @return:true if successful.
    • finish As Boolean
      Flushes any pending data and closes output file. If writing to an
      OutputStream, the stream is not closed.
    • setPosition (x As Int, y As Int)
      Sets the GIF frame position. The position is 0,0 by default.
      Useful for only updating a section of the image
      w: int frame width.
      h: int frame width.
    • setSize (w As Int, h As Int)
      Sets the GIF frame size. The default size is the size of the first frame
      added if this method is not invoked.
      w: int frame width.
      h: int frame width.
    • start (os As OutputStream) As Boolean
      Initiates GIF file creation on the given stream. The stream is not closed
      automatically.
      os: OutputStream on which GIF images are written.
      Return type: @return:false if initial write failed.


Credits:

As for the original version, code is free for any kind of usages, but you must refer to the Unisys LZW patent for restrictions on use of the associated LZWEncoder class.

NOTE:

My BitCloud library is not included. This is just used to write an bytearray to a file from the outputstream.
There are some examples to write a bytearray to a file on the forums.

Tomas
 

Attachments

  • GifEncoder.zip
    32.1 KB · Views: 1,140
Last edited:

Highwinder

Active Member
Licensed User
Longtime User
Source?

Tomas,

Thanks again for another library. :)

What is the source that the animated GIF file is created from? Camera? Screen capture?
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Tomas,

Thanks again for another library. :)

What is the source that the animated GIF file is created from? Camera? Screen capture?

What do you mean with "the source that the animated GIF file is created from?".

The library encodes several bitmap images to a gif file.

Tomas
 

vb1992

Well-Known Member
Licensed User
Longtime User
It's from the photo's/images you supply to the library.

You could take a few snap shots with the camera (in memory)
to create these (motion) images and send it through this library...


Sub Camera_PictureTaken (Data() As Byte)

' set the size of the camera to be small

Dim in As InputStream
in.InitializeFromBytesArray(Data)

Dim bmp As Bitmap
bmp.Initialize2(in)

Gif89.addFrame (bmp)

End Sub
 
Last edited:

mcmanu

Active Member
Licensed User
Longtime User
Hi

is it possible to use an animation when Voice recognition is Listening?
I tried it and the Animation stops when the voice recognition is listening.
Is there a way to overcome this issue?
 
Last edited:

malakie

Member
Licensed User
Longtime User
New to this..

I am new to Android coding...

I am trying to play and animated gif on my phone from Basic4Android.

I downloaded your attached file. It shows up in the LIBS list on the right side of the screen.. How do I actually use it?

I do not see any control or object to place on the design screen... any help?
 

troarty

New Member
Licensed User
Longtime User
I'd really like to be able to create animated gifs using basic4android...Can you point me to an example of writing they bytearray from the outputstream to a file?

Tom
 

Sytek

Active Member
Licensed User
Longtime User
I am new to Android coding...

I am trying to play and animated gif on my phone from Basic4Android.

I downloaded your attached file. It shows up in the LIBS list on the right side of the screen.. How do I actually use it?

I do not see any control or object to place on the design screen... any help?

..You can use it as follows
E.G.
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim vvv As RSAnimatedGifEncoder
End Sub

...Then you can call its properties vvv.start

Please Read the Beginners Guide
http://www.b4x.com/forum/basic4android-getting-started-tutorials/9578-beginners-guide.html#post53042
 

troarty

New Member
Licensed User
Longtime User
Can anyone point me to an example of writing the bytearray from the outputstream to a file? I get confused because the bytearray is already on the outputstream and yet I need to read from it in order to write to an outputstream (the file)

Tom
 
Top