Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Support cropping based on original image size #33

Closed
rharter opened this issue Feb 2, 2016 · 4 comments
Closed

Support cropping based on original image size #33

rharter opened this issue Feb 2, 2016 · 4 comments

Comments

@rharter
Copy link
Contributor

rharter commented Feb 2, 2016

Currently, the cropped image can be significantly degraded from the original since the cropping is based on the view's dimensions. If the image is significantly larger than the view, the cropped image will be the size of the view, which isn't ideal, especially on budget devices.

Regardless of view size, I think the cropping should be based on the original image size, since the representation on screen is simply proportional to the actual file.

@eveliotc
Copy link
Contributor

eveliotc commented Feb 2, 2016

Although having output to match view dimensions was intended (literally wysiwyg), agreed that is not ideal and this would be a great enhancement for third party developers, handling original source is a bit of a challenge and we should approach it using subsampling.

@soxunyi
Copy link

soxunyi commented Aug 16, 2016

@nshmura Do best

@konecnyna
Copy link

konecnyna commented Jan 8, 2017

I would love to have this feature too. The way the current cropping works
is using the viewport dimensions instead of the original bitmap dimensions.

    @Nullable
    public Bitmap crop() {
        if (bitmap == null) {
            return null;
        }


        if (true) {
            return cropFullResolution();
        }

        final Bitmap src = bitmap;
        final Bitmap.Config srcConfig = src.getConfig();
        final Bitmap.Config config = srcConfig == null ? Bitmap.Config.ARGB_8888 : srcConfig;
        final int viewportHeight = touchManager.getViewportHeight();
        final int viewportWidth = touchManager.getViewportWidth();

        final Bitmap dst = Bitmap.createBitmap(viewportWidth, viewportHeight, config);

        Canvas canvas = new Canvas(dst);
        final int left = (getWidth() - viewportWidth) / 2;
        final int top = (getHeight() - viewportHeight) / 2;
        canvas.translate(-left, -top);

        drawBitmap(canvas);

        return dst;
    }

It's using the viewportWidth to create the cropped bitmap which I would think change per the screen density of the phone. Two identical crops on two different phones would have different resolutions.

We have access to the original bitmap in this scope but i'm having trouble trying to translate cropping logic to respect the original bitmap.

@dschaller
Copy link

Thank you for you contribution to this repository.

Closing this contribution as this repository is being archived.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants