Reputation: 141
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 .
Upvotes: 1
Views: 1262
Reputation: 2576
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:
Upvotes: 3
Reputation: 71
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.
Upvotes: 1