如何在Android中以编程方式将PNG图像转换为GIF

时间:2014-06-26 10:36:02

标签: android android-imageview

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

1 个答案:

答案 0 :(得分:0)

使用Gif encoder类来实现这一目标。 例如,您可以使用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();