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 .
- use gif Encoder to merge images and create animationDivyesh Patel– Divyesh Patel2017-05-03 10:54:16 +00:00Commented May 3, 2017 at 10:54
- but how it possible?Idrish Multani– Idrish Multani2017-05-03 10:57:15 +00:00Commented May 3, 2017 at 10:57
- can you give me a any code in ans?Idrish Multani– Idrish Multani2017-05-03 10:57:39 +00:00Commented May 3, 2017 at 10:57
2 Answers
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:
9 Comments
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.