B4J Question Possible to rotate an image in imageview?

tufanv

Expert
Licensed User
Hello,

Is it possible to rotate an image in an imageview? I couldnt find a similar example for it.

thanks
 

MrKim

Well-Known Member
Licensed User
Hi:

Add Xui library, declare the imageview as B4XView and use
B4X:
ImageView1.Rotation = 90
There is a problem with this, If the image is not square and it was loaded using xui.LoadBitmapResize then when you rotate it lops off part of the the image.
Edit: Statement above is not accurate, HOWEVER it you have the imageview top at 0 or left at 0 it won't automatically move the control to stay inside the container and will lop off part of the picture.
This is how it loads.
1593512563750.png

This is after rotating. Note that is still says the imageview Top is 0 but it is cutting off the top of the picture. If I move the imageview down it is all there.
1593512680810.png

I test this with the Imageview anchor set to all three configuations Top and left, bottom and right and Centered and always got the same results.
 
Last edited:

MrKim

Well-Known Member
Licensed User
Well, I started this thread to solve another part of the problem which was saving the image rotated and it wound up being the fix for both. Instead of using imageview.Rotation = XX or PictureImg.SetRotationAnimated(5, XX)
this works better:
B4X:
    Dim X As B4XBitmap = PictureImg.GetBitmap
    X = X.Rotate(90)
    PictureImg.SetBitmap(X)
Doesn't cut off the picture and actually rotates the image so when it is save it is restored correctly.
 

oparra

Active Member
Licensed User
Well, I started this thread to solve another part of the problem which was saving the image rotated and it wound up being the fix for both. Instead of using imageview.Rotation = XX or PictureImg.SetRotationAnimated(5, XX)
this works better:
B4X:
    Dim X As B4XBitmap = PictureImg.GetBitmap
    X = X.Rotate(90)
    PictureImg.SetBitmap(X)
Doesn't cut off the picture and actually rotates the image so when it is save it is restored correctly.
Yes.
 
Top