Это мой код для создания Gif-файла, однако создаваемый им Gif-файл имеет размер 4,9 МБ и содержит 32 кадра
@Override
protected Void doInBackground(Void... voids) {
String dstFile = "result.gif";
final String filePath = Environment.getExternalStorageDirectory() + File.separator + dstFile;
int width = 640;
int height = 480;
int delayMs = 100;
GifEncoder gifEncoder = new GifEncoder();
try {
gifEncoder.init(width, height, filePath, GifEncoder.EncodingType.ENCODING_TYPE_NORMAL_LOW_MEMORY);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
gifEncoder.setDither(true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] Byte;
Bitmap resized;
int j;
for ( j = 0; j < 32; j++) {
Utilities.BoomerangeFrames[j].compress(Bitmap.CompressFormat.WEBP,20,bos);
Byte = bos.toByteArray();
resized = BitmapFactory.decodeByteArray(Byte,0,Byte.length);
resized = Bitmap.createScaledBitmap( Utilities.BoomerangeFrames[j], width, height, true);
gifEncoder.encodeFrame(resized, delayMs);
bos.reset();
}
gifEncoder.close();
return null;
}
}
Я хочу знать, есть ли какое-нибудь решение для уменьшения размера моего файла gif до 1 МБ.