How to make simple image to animated image like GIF?

筅森魡賤 提交于 2019-12-24 09:27:51

问题


I wont to make simple image to Animated image like GIF.I can select the image for gallery and store in image file.But, How i can modify image file to animated image or GIF File .


回答1:


you have to select images you want to make GIF, then use bitmaps and run code in background Thread/Asynchtask:

Here i used Drawable, in your case convert images into bitmap and use it.

            Bitmap one=BitmapFactory.decodeResource(getResources(),R.drawable.neon0);
            Bitmap two=BitmapFactory.decodeResource(getResources(),R.drawable.neon1);
            Bitmap three=BitmapFactory.decodeResource(getResources(),R.drawable.neon2);


            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            AnimatedGifEncoder encoder = new AnimatedGifEncoder();
            encoder.start(bos);


            encoder.addFrame(one);
            encoder.addFrame(two);
            encoder.addFrame(three);
            encoder.finish();

            FileOutputStream outStream;
            try{
                outStream = new FileOutputStream(Environment.getExternalStorageDirectory().getPath() + 
                "/IMAGES_GIF/" + "animated.gif");
                outStream.write(bos.toByteArray());
                outStream.close();
            }catch(Exception e){
                e.printStackTrace();
            }

Get Class from:

https://gist.githubusercontent.com/wasabeef/8785346/raw/53a15d99062a382690275ef5666174139b32edb5/AnimatedGifEncoder.java




回答2:


This question needs a lot more information. Is the file already a GIF and it is not animating or are you trying to convert an image to a GIF? The latter is not possible, a GIF is a series of images.

You must create the GIF elsewhere and it is easiest to use a library like Glide (https://github.com/bumptech/glide) or Picasso (http://square.github.io/picasso/) to load the GIF.



来源:https://stackoverflow.com/questions/43757632/how-to-make-simple-image-to-animated-image-like-gif

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!