BurstLinker 是一个简单的 C ++ GIF 编码库。可以在 Android,Windows,Linux 或其他平台上轻松使用它。
安卓平台
Gradle:
implementation 'com.bilibili:burst-linker:latest-version'
Android Studio 3.0.1
NDK r16
int delayMs = 1000; String filePath = getExternalCacheDir() + File.separator + "out.gif"; BurstLinker burstLinker = new BurstLinker(); try { burstLinker.init(width, height, filePath); Bitmap colorBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(colorBitmap); Paint p = new Paint(); int[] colors = new int[]{0xFFF00000, 0xFFFFFF00, 0xFFFFFFFF}; for (int color : colors) { p.setColor(color); canvas.drawRect(0, 0, width, height, p); burstLinker.connect(colorBitmap, BurstLinker.OCTREE_QUANTIZER, BurstLinker.NO_DITHER, 0, 0, delayMs); } } catch (GifEncodeException e) { e.printStackTrace(); } finally { burstLinker.release(); }