0

I am working on a functionality which allow the user to click the photo for as many times as they want and then create a gif from those photos.If anyone has any idea regarding this then it will be helpful for me.Please help me out with this.Thanks in Advance!

Aastha Doshi
  • 147
  • 1
  • 14
  • can have a look on https://stackoverflow.com/questions/16331437/how-to-create-an-animated-gif-from-jpegs-in-android-development or https://stackoverflow.com/questions/8515350/how-to-make-gif-image-by-two-bitmaps-in-android might it help you , if it works for you let me know. – Prags Nov 22 '17 at 06:41
  • Try ffmpeg lib for this. – Andy Developer Nov 22 '17 at 06:46

1 Answers1

0

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

    public void convertGif(String imagepath){

     FileOutputStream outStream = null;
     try {
        outStream = new FileOutputStream(/sdcard/generate_gif/test.gif);//This is storage path of gif
        outStream.write(generateGIF(imagepath));
        outStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

Response from this answer here

Dilip
  • 2,622
  • 1
  • 20
  • 27
  • I need to take the picture from camera then create a gif from the captured image.I had already taken the picture from camera and stored it into one directory but now how can i create the gif from it this is my question – Aastha Doshi Nov 22 '17 at 07:12
  • So put above code in one method and pass path to that method for usages – Dilip Nov 22 '17 at 07:15
  • what is getBitmapArray() method? – Aastha Doshi Nov 22 '17 at 07:16