PhotoEditor: Problem with image scaling
I came across two problems while working with the library:
- 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;
}
- 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).
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 7
- Comments: 20 (6 by maintainers)
Commits related to this issue
- Merge pull request #10 from Agfct/test_image_crop_to_remove_white_line Test image crop to remove white line — committed to Agfct/PhotoEditor by Agfct 6 years ago
hi @burhanrashid52 i’ve done some quick combination between your project and https://github.com/siwangqishiq/ImageEditor-Android so that i can save a big resolution image with stickers. Check it out at: https://github.com/fandygotama-tokobagus/PhotoEditor, please note that this is not 100% done as the project still missing some feature like e.g.: undo/redo brush, typeface and other things 😃