如何在Android程序中将PNG图像转换为GIF格式?

时间:2021-03-16 21:20:31

I am working an app in which I want to convert images from png format to gif format please help me or some suggestion for that

我正在开发一个应用程序,我想要将图片从png格式转换为gif格式,请帮助我或一些建议。

1 个解决方案

#1


0  

Use a Gif encoder class to achieve that. For example, you could use https://github.com/nbadal/android-gif-encoder/blob/master/GifEncoder.java

使用一个Gif编码器类来实现它。例如,您可以使用https://github.com/nbadal/android-gif-encoder/blob/master/GifEncoder.java。

ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
  AnimatedGifEncoder encoder = new AnimatedGifEncoder();
  encoder.start(bos);
  encoder.addFrame(image);
  encoder.finish();
  byte[] array = bos.toByteArray();

  // Save to file
  File output = new File("output.gif");
  FileOutputStream fos = new FileOutputStream(output.getPath());
  fos.write(array);
  fos.close();

#1


0  

Use a Gif encoder class to achieve that. For example, you could use https://github.com/nbadal/android-gif-encoder/blob/master/GifEncoder.java

使用一个Gif编码器类来实现它。例如,您可以使用https://github.com/nbadal/android-gif-encoder/blob/master/GifEncoder.java。

ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
  AnimatedGifEncoder encoder = new AnimatedGifEncoder();
  encoder.start(bos);
  encoder.addFrame(image);
  encoder.finish();
  byte[] array = bos.toByteArray();

  // Save to file
  File output = new File("output.gif");
  FileOutputStream fos = new FileOutputStream(output.getPath());
  fos.write(array);
  fos.close();