avito-tech / krop

Small widget for image cropping in Instagram-like style
MIT License
126 stars 18 forks source link

Add utility to get cropped bitmap with given transformation without KropView #28

Closed trebouillon closed 3 years ago

trebouillon commented 3 years ago

It would be nice to have the possibility to extract a cropped image from a given bitmap without using the Kropview.

Imagine the following case:

eugene-krivobokov commented 3 years ago

@Kutashov , cc

Kutashov commented 3 years ago

Hi, Thomas.

Transformation data is dedicated to restore old kropview local state, not for obtaining cropped bitmap. Along with transformation, some context and kropview settings are used for restoring original view's state and obtaining cropped bitmap later. All in all, it ain't designed for your use case.

We might think on some other entity for this purpose. Current solution is fair robust: you get what you see. But assuming you have a code bitmap.getCroppedBitmap(rect), you can get UB, if wrong bitmap is used with saved rect.

Have you considered saving cropped bitmap on step 2?

trebouillon commented 3 years ago

Hey, thanks for the response. Sure, it needs to be in a different format, but something which stores the data in a format I could use for Bitmap.createBitmap(...).

This is my current workaround now, I store this cropped file, upload it and delete it after upload. As I am working with work manager to do this I need to kind of keep track of this file. I thought cropping the original image on the fly would be best, as workmanager takes maximum 10 KB of bytes for data processing.

Kutashov commented 3 years ago

@trebouillon Hi. I've added implementation, kindly, check, if it's clear enough.

trebouillon commented 3 years ago

Alright, sounds great. I will give this a try 👍

Kutashov commented 3 years ago

Released in 0.64

trebouillon commented 3 years ago

Hey, I updated my code and I am using it. Thanks for the quick implementation :)