B4J Library [B4X] [XUI] xResizeAndCrop

LucaMs

Expert
Licensed User
Longtime User
Conclusion: your library works great. (only that... "I can't drag the bottom edge all the way down"; maybe adding a button: "Select all")
In the demo and in my project we should get the dimensions from the file and pass these to the LoadBitmap method (and LoadBitmapResize would not be needed)
 

LucaMs

Expert
Licensed User
Longtime User
Not so easy for B4X (multiplatform).
B4A solution:
B4X:
Private Sub btnSelectImage_Click
    ShowContentChooser
    Wait For ContentChooser_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then
        Dim bmp As Bitmap
        bmp.Initialize(Dir, FileName)
'        xResizeAndCrop1.Image = xui.LoadBitmapResize(Dir, FileName, 4000, 4000, True)
        xResizeAndCrop1.Image = bmp
        xResizeAndCrop1.mBase.Color = xui.Color_Blue
        lblRotate.Visible = True
    End If
End Sub

The log "is perfect", this way.
 

klaus

Expert
Licensed User
Longtime User
I retested the demo program and replaced:
B4X:
xResizeAndCrop1.Image = xui.LoadBitmapResize(ImageDir, ImageFileName, 2000, 2000, True)
by
B4X:
xResizeAndCrop1.Image = xui.LoadBitmap(ImageDir, ImageFileName)
and now I get the correct values.
The original image: 6000 * 4000
And the Logs: 5994 * 4000
The 6 pixel difference is due to the fact that the crop cursor resolution is not 1 pixel.

I had used LoadBitmapResize in the demo program to minimize the memory needed.
But this is only in the demo program and is not a problem of the xResizeAndCrop library.

I had a short look at your program.
The problem is in this line:
B4X:
xResizeAndCrop1.Image = xui.LoadBitmapResize(Dir, FileName, B4XImageView1.mBase.Width, B4XImageView1.mBase.Height, True)
You resize the image to adapt it to your B4XImageView1 object.
If you want the image with the original resolution you must use :
B4X:
xui.LoadBitmap(Dir, FileName)
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Yes, Klaus, it is "the same" I wrote in #40.

Thank you.
 

klaus

Expert
Licensed User
Longtime User
The returned bitmap has round corners, which is not the case in your project.
In your project, you could use a B4XView/Panel instead of the B4XImageView and and set it as the CroppedView property.
The advantage is that the rounded corners are updated directly, even when you move the handles.
I will update the library hopefully tomorrow or on Sunday. The demo project will become a B4XProject.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
The xResizeAnd Crop Class has been updated to version 1.6 in the first post.
Added Circle and round corner crop
Added RoundCorner and CornerRadius properties.
The library needs the BitmapCreator library.
 

GeoT

Active Member
Licensed User
Longtime User
Hello.
Is there a way to make the initial crop box the size of the image in case you just want to rotate the image when WidthHeightRatio = "None"?
Thank you.
 
Last edited:

GeoT

Active Member
Licensed User
Longtime User
Ok.
There is also no indicator that the marker box occupies the entire image without missing any pixels, right?
Thank you.
 

klaus

Expert
Licensed User
Longtime User
Yes.
I have never tested it.
What i can do is, when the width / height ratio is none, to set the crop window to the entire image.
In this case, the entire image with all pixels is taken.
Can you please test the joined version ?

Edit: 2023.03.28
Removed the library file, it has been update in the first post.
 
Last edited:

GeoT

Active Member
Licensed User
Longtime User
When measuring bitmaps. Reading from logger:

Samsung Galaxy Grand Prime+ with Android 6.1
Original size (width x height)Device in portraitDevice in landscape
400 x 600400 x 601400 x 602
800 x 1067800 x 1068800 x 1069
800 x 533800 x 532800 x 535
3264 x 24483264 x 24453264 x 2454
250 x 250250 x 250251 x 251
1440 x 14401440 x 14401440 x 1440

Samsung Galaxy A50 with Android 11
Original size (width x height)Device in portraitDevice in landscape
400 x 600400 x 600400 x 600
800 x 1067800 x 1067800 x 1070
800 x 533800 x 533800 x 534
3264 x 24483264 x 24473264 x 2448
250 x 250250 x 250251 x 251
1440 x 14401440 x 14401440 x 1440

I attach my example in B4A. Now I get the image from DirAssets first, but you can load the images with the load button.
 

Attachments

  • CropAndRotate.zip
    107.1 KB · Views: 144
Last edited:

GeoT

Active Member
Licensed User
Longtime User
Only the value in bold will change.

Samsung Galaxy Grand Prime+ with Android 6.1
Original size (width x height)Device in portraitDevice in landscape
400 x 600400 x 601400 x 602
800 x 1067800 x 1068800 x 1069
800 x 533800 x 532800 x 535
3264 x 24483264 x 24453264 x 2454
250 x 250250 x 250251 x 251
1440 x 14401440 x 14401440 x 1440

Samsung Galaxy A50 with Android 11
Original size (width x height)Device in portraitDevice in landscape
400 x 600400 x 600400 x 600
800 x 1067800 x 1067800 x 1070
800 x 533800 x 533800 x 534
3264 x 24483264 x 24483264 x 2448
250 x 250250 x 250251 x 251
1440 x 14401440 x 14401440 x 1440

Thank you.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…