-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
Feature Request
For one of my projects, it was needed to use a bitmap compress to JPEG. I would like to be able to choose the compress format in the toDataURL.
Why it is needed
The picture I use is too big, I would like to be able to compress in JPEG.
Possible implementation
We could add a new parameter to the toDataURL function. It could be a string param like 'PNG' or 'JPEG'
Code sample
String toDataURL(int width, int height, string compressionFormat) {
Bitmap bitmap = Bitmap.createBitmap(
width,
height,
Bitmap.Config.ARGB_8888);
clearChildCache();
drawChildren(new Canvas(bitmap));
clearChildCache();
this.invalidate();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
if(compressionFormat == "jpeg") {
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
}else {
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
}
bitmap.recycle();
byte[] bitmapBytes = stream.toByteArray();
return Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
}LRNZ09, Pakile and Woynert