Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export in JPEG #1588

Open
guillaume-lecomte opened this issue May 12, 2021 · 0 comments
Open

Export in JPEG #1588

guillaume-lecomte opened this issue May 12, 2021 · 0 comments

Comments

@guillaume-lecomte
Copy link

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);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants