如何在Android中创建的JPEG动画GIF(发展)动画、如何在、JPEG、Android

2023-09-12 04:00:53 作者:只闻花香不谈悲喜,喝茶读书不争朝夕。今日小编为您精心设计一些

我要寻找一个简单的方法来创建的GIF动画的原生Android应用程序。 源文件应为JPEG(从相机或什么都)和输出应该被保存为GIF在设备上。

I am looking for a simple way to create an animated GIF in a native Android application. The source files should be JPEG (from camera or what ever) and the output should be saved as GIF on the device.

我不想知道如何播放动画或GIF动画文件。

需要明确的是:我想知道如何把一个图像帧一帧变成了电影,然后将其保存为.gif文件

To be clear: I want to know how to put single images frame by frame into a "movie" and then save it as a .gif file.

例如。 此应用可以想得到我想做的事情。

e.g. This App can do want I want to do.

推荐答案

请参阅此解决方案。

https://github.com/nbadal/android-gif-en$c$cr

这是本帖的Andr​​oid版本。

It's an Android version of this post.

http://www.jappit.com/blog/2008/12/04/j2me-animated-gif-en$c$cr/

要使用这个类,下面是一个例子的辅助方法来生成GIF字节数组。这里注意的getBitmapArray()函数是一个方法,在一次返回在图像适配器中的所有位图文件。因此,输入是一个适配器所有的位图文件,输出是一个字节数组,你可以写入文件。

To use this class, here is an example helper method to generate GIF byte array. Note here the getBitmapArray() function is a method to return all the Bitmap files in an image adapter at once. So the input is all the Bitmap files in one adapter, the output is a byte array which you can write to the file.

public byte[] generateGIF() {
    ArrayList<Bitmap> bitmaps = adapter.getBitmapArray();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    AnimatedGifEncoder encoder = new AnimatedGifEncoder();
    encoder.start(bos);
    for (Bitmap bitmap : bitmaps) {
        encoder.addFrame(bitmap);
    }
    encoder.finish();
    return bos.toByteArray();
}

要使用此功能,请执行下列操作,那么你可以将文件保存到SD卡。

To use this function, do the following then you can save the file into SDcard.

FileOutputStream outStream = null;
        try{
            outStream = new FileOutputStream("/sdcard/generate_gif/test.gif");
            outStream.write(generateGIF());
            outStream.close();
        }catch(Exception e){
            e.printStackTrace();
        }