Creating GIFs Take So Long In Android

I am creating an application that captures capture snapshots and creates GIFs as output. My problem is creating GIFs from a sequence of images takes so long, regardless of the resolution of the 320x240 images. I am using the AnimatedGifEncoder class to encode GIFs. as follows link .

My GIF creation code is as follows

 private void saveGifImage() { FileOutputStream outStream = String fileName = "test.gif"; try { File file = new File(Environment.getExternalStorageDirectory() + "/gif_convertor/sample/"); if (!file.exists()) file.mkdirs(); File file1 = new File(file + File.separator + if (file1.exists()) { } else { try { // file1.mkdirs(); file1.createNewFile(); } catch (Exception e) { } } outStream = new FileOutputStream(file1); Log.d("Location", file1.getPath().toString()); outStream.write(generateGIF()); outStream.close(); } catch (Exception e) { e.printStackTrace(); } finally { DialogUtils.stopProgressDisplay(); } } private byte[] generateGIF() { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AnimatedGifEncoder encoder = new AnimatedGifEncoder(); encoder.start(bos); encoder.delay = 33; // 50 means 0.5 seconds ( 100 value is equivalent to 1 seconds) encoder.repeat = 0; // 0 means repeat forever, other n positive integer means n times repeat , -1 means no repeat encoder.sizeSet = true; // resize allowed with true flag encoder.width = 320; encoder.height = 240; File tempDir = new File(getActivity().getExternalFilesDir(null), "temp"); if (tempDir.exists()) { for (File file : tempDir.listFiles()) { Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); encoder.addFrame(bitmap); } } encoder.finish(); return bos.toByteArray(); } 
+5
source share

All Articles