Android Question xResizeAndCrop - Big Pictures

artsoft

Active Member
Licensed User
Longtime User
Hi all!

I use the xResizeAndCrop.b4xlib control in my app in order to crop my pictures.

Lib page:
https://www.b4x.com/android/forum/threads/b4x-xui-xresizeandcrop.100109/

The example (which is also provided with the lib) and controls works fine if the loaded picture is not so big (i. e. 4000 x 3000 pixels).

But if I try to load an image with big dimensions (i. e. 8000 x 6000 pixels / made by my camera in the 48MP mode) then the crop control is always empty ... in my app and in the example.

The normal imageview control doesnt have any problems with this bitmap size / dimensions.

What could I do now?
Thx in advance for any help.

Best regards
ARTsoft
 

klaus

Expert
Licensed User
Longtime User
I tested the demo program with a picture with 6000 / 4000 pixels on my Samsung Galaxy S10, Android 11
And it works as expected.

Then I tested it on my Samsung Tablet S2, Android 7
And I get an Out of memory error message.
Then I tested it, after adding the line below to the Manifest Editor:
B4X:
SetApplicationAttribute(android:largeHeap,"true")
It does not throw an error but the screen is flickering, even in Release mode, but it works.
The problem is that the entire bitmap is loaded which gives a memory request of width * height * 4 bytes.

Try to add the line above in the Manifest Editor.

Or, in the xResizeAndCrop module in the LoadImage routine, you could replace this line
B4X:
    xbmpImage = xui.LoadBitmap(Dir, FileName)
by this one.
B4X:
xbmpImage = xui.LoadBitmapResize(Dir, FileName, 3000, 2000, True)
You might adapt the width and height values to your needs.
Of course, this will reduce the quality of the image, because it is downsized.

EDIT:
Do not use the modification above but use the solution in post #4.
 
Last edited:
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
Hi Klaus!

Thanks for your quick answer and the tests made on your side.

Unfort. the "largeHeap" was already set in my manifest. My pictures are bigger than yours - regarding the dimensions (see above: 8000 x 6000 pixels, 48 MP and the image quality is perfect in my case).

Your solution (to load the bitmap with LoadBitmapResize command) is ok for me, because my app will anyway decrease the size and the quality of the image finally before encrypt and store it. But you are right: The source image quality is very descreased by doing this. You have to know that my app is a power safe app which is able to encrypt all private images from any image source (local pic file, cloud pic file, camera picture). So the content is more important than the image quality.

Do you see a way to update your lib in a next version to avoid such exceptions or to increase the internal performance while handling an image?
This would be great.

Many years ago, I heard that there is an additional way to crop images by using the internal CROP INTENT mechansim.
How to do this within B4A? Do you know how to use the internal CROP app from the smartphone?

Thx again, dear Klaus.

Regards
ARTsoft
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I had a further look at the problem.
I will not modify the class because it is cross-polatform and the limits depend on the platform and the devices.
But the solution in my previous post is not the good one?
Instead of modifying the routine in the class you should modify it in your code:
Instead of:
B4X:
xResizeAndCrop1.LoadImage(ImageDir, ImageFileName)
You could use:
B4X:
xResizeAndCrop1.Image = xui.LoadBitmapResize(ImageDir, ImageFileName, 2000, 2000, True)
Of course the values of 2000 are for example, you need to adapt the values.
I will modify the demo programs accordingly.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Not hindered by any knowledge in the application of your program, I wonder whether it would not be better to apply a dichotomy in your program.

You can choose to display the images in your program with a lower acceptable resolution as Klaus specifies, and they will be also displayed faster. With an option to download the high resolution so that it can be viewed outside your program, the details can be viewed at the highest resolution if needed.
 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
I had a further look at the problem.
I will not modify the class because it is cross-polatform and the limits depend on the platform and the devices.
But the solution in my previous post is not the good one?
Instead of modifying the routine in the class you should modify it in your code:
Instead of:
B4X:
xResizeAndCrop1.LoadImage(ImageDir, ImageFileName)
You could use:
B4X:
xResizeAndCrop1.Image = xui.LoadBitmapResize(ImageDir, ImageFileName, 2000, 2000, True)
Of course the values of 2000 are for example, you need to adapt the values.
I will modify the demo programs accordingly.

___________________________________

Perfect, Klaus!

This helps a lot. I fixed my code and it's working perfectly now.

For the recalculation of the new pixel dimensions W x H, I had to be careful: sometimes W is greater than H or vice versa.

I am asking me, why the command LoadBitmapResize has pixel dimensions for new W and new H ... AND ... an additional parameter for keeping the aspect ration of the image.

What would happen, if the source image has (i. e.) a dimension of 6000 x 4000 pixels and I use this command: xui.LoadBitmapResize(ImageDir, ImageFileName, 2000, 2000, True)?

True means that the aspect ration should be kept, but what about the new W = 2000 and the new H = 2000???

I am very thankful, Klaus. Thanks a lot for your quick help.

Regards
ARTsoft :)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I suggested intentionally the two values the same and KeepAspectRatio to True.
What happens?
If the bitmap is landscape and its width > 2000 then the width = 2000 and the height according to the aspect ratio.
If the bitmap is portrait and its height > 2000 then the height = 2000 and the width according to the aspect ratio.
I rechecked it before posting.
 
Upvote 0
Top