如何从stickerview库保存gif?

问题描述 投票:0回答:1

使用的库:https://github.com/wuapnjie/StickerView

我正在尝试通过在选定的/捕获的图像上放置贴纸,gif来创建照片编辑器。通过以下代码实现将gif放置在imageview上:

try {
     final Drawable drawable2 = new GifDrawable(getResources(), stickerId);

     drawable2.setCallback(new Drawable.Callback() {
         @Override
         public void invalidateDrawable(Drawable who) {
             stickerView.invalidate();

         }

         @Override
         public void scheduleDrawable(Drawable who, Runnable what, long when) {
             stickerView.invalidate();
         }

         @Override
         public void unscheduleDrawable(Drawable who, Runnable what) {
             stickerView.invalidate();
         }
     });

     stickerView.addSticker(new DrawableSticker(drawable2));


 } catch (IOException e) {
     e.printStackTrace();
 }

但是在保存文件时。所选的gif的最后一帧仅被捕获并保存为图像,但是我想在图像上播放gif。Gif保存代码:

 public static File saveImageToGalleryGif(@NonNull File file, @NonNull Bitmap bmp) {

     Log.d(TAG, bmp.toString());
     if (bmp == null) {
         throw new IllegalArgumentException("bmp should not be null");
     }
     // File outputFile = new File("/sdcard/generate_gif/test.gif");
     File outputFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "shared_gif" + System.currentTimeMillis() + ".gif");
     FileOutputStream fos = null;
     try {
         fos = new FileOutputStream(outputFile);
     } catch (FileNotFoundException e) {
         e.printStackTrace();
     }

     if (fos != null) {
         AnimatedGifEncoder gifEncoder = new AnimatedGifEncoder();
         gifEncoder.start(fos);
         gifEncoder.addFrame(bmp);


         gifEncoder.finish();
     }

     return file;
     }

[请帮助我保存gif文件。

java android imageview gif
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.