Skip to content

Problem with image scaling #10

@siberianbearr

Description

@siberianbearr

I came across two problems while working with the library:

  1. If the image is bigger than the max OpenGL texture size(which is different depending on the device), the image won't be shown. I had this problem before when trying to display a large image in an ImageView. This is less a problem with the library but with Android itself, but nonetheless the library could handle that. My solution was to simply scale the image down to 2048px, this should work on most devices.
public static Bitmap transformBitmapTo2048px(Bitmap source){
        if(source.getHeight() <= 2048 && source.getWidth() <= 2048)
            return source;

        int targetWidth;
        int targetHeight;

        double aspectRatio = (double) source.getHeight() / (double) source.getWidth();

        if(source.getWidth() >= source.getHeight()){
            targetWidth = 2048;
            targetHeight = (int)(2048 * aspectRatio);
        } else {
            targetHeight = 2048;
            targetWidth = (int)(2048 / aspectRatio);
        }

        Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
        if (result != source) {
            // Same bitmap is returned if sizes are the same
            source.recycle();
        }
        return result;
}
  1. The current implementation for editing an image works basically by doing the image processing on the screen and the taking the contents of that to save the image. The problem with that is that the image get scaled down, possibly a lot. For example, if you have a picture in landscape, it will be scaled down quite a lot to fit into the ImageView. In my case, the PhotoEditorView fits the whole screen, so if I save the image, it will be exactly the size of my screen, and the actual (landscape) image is only a small part of that image.
    The correct approach would be to have an internal representation of the image and do all the processing on that. This would allow to keep the original size of the image (you can still show the image scaled down to fix problem 1).

Metadata

Metadata

Labels

bugSomething isn't workinghelp wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions