avito-tech / krop

Small widget for image cropping in Instagram-like style

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add utility to get cropped bitmap with given transformation without KropView

trebouillon opened this issue · comments

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:

  • I have a view and crop the image
  • I just want to store the transformation data
  • at a later point I want to load the original bitmap and get the cropped bitmap with the stored transformation data, but without setting the bitmap on the Kropview and instead directly creating the cropped bitmap

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?

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.

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

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

Released in 0.64

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