B4J Question B4J non-UI: How to rotate Image and write result to file?

johnerikson

Active Member
Licensed User
Longtime User
I wish to obtain the same result with B4j non-ui as in B4a below!

B4X:
'B4a code

Dim bmp As Bitmap
Dim rbmp As RSImageProcessing

rbmp.Initialize
bmp.Initialize( sPathRot, sImg)
bmp = rbmp.Rotate(bmp, 90)
rbmp.writeBitmapToFile(bmp,sPathRot ,sImg,  100 )

How?
 

Daestrum

Expert
Licensed User
Longtime User
Not sure if this is the best way as I don't use B4Xthingy very much but it seems to do what you want.

You need to add the JFX library and XUI library

B4X:
Sub Process_Globals
 Dim xu As XUI
 Dim fx As JFX
End Sub
Sub AppStart (Args() As String)
 Dim bm As B4XBitmap = xu.LoadBitmap("c:/temp" , "hannah.jpg")
 bm = bm.Rotate(90)
 bm.WriteToStream(File.OpenOutput("c:/temp","hannahRotated90.jpg",False),100,"JPEG")
End Sub
 
Upvote 0

johnerikson

Active Member
Licensed User
Longtime User
Thanks!
It works to rotate the image, but the EXIF information lost GPS data among other such data! I haven't check all the EXIF values!
The same happens unfortunately with the B4A code!
 
Upvote 0

johnerikson

Active Member
Licensed User
Longtime User
What does BM. Rotate (90) do?
Does BM. Rotate (x) execute only changes to the EXIF values of the orientation and is then updated in the image's EXIF data
or are new x/Y values calculated on the image pixels to rotate the image
or both of those processes?
I use ABMaterial to view the images and ABMaterial does not read the EXIF data for the orientation but only the geometry. This indicates that geomytry data is not changed with the bm.Rotate(x)?
Which is not logical as the EXIF information is lost!
Therefore, it makes no sense for me to change the EXIF data either!
Strange and confusing!
 
Upvote 0

johnerikson

Active Member
Licensed User
Longtime User
After further investigation, it has been found that if I convert the image to .bmp and rotate it in the photo program (GIMP2) and convert it back to .jpg so finally the image is displayed in the ABMaterial with the correct orientation. If I rotate it again with
B4X:
      Dim bm As B4XBitmap = Xu. 
      LoadBitmap (ti. Pathname, ti. imgid) 
      BM = BM. Rotate (90) 
      bm. WriteToStream (File. Openoutput (ti. Pathname, ti. Imgid, False),100, "JPEG")
then it is not rotated correctly in ABMaterial! However, I see in the icon in the folder and if I open it with foroprogrammet then it is rotated correct.
Bm.Rotate and the photo programs do not do the same rotation-procedure!
Interesting!
Seems impossible to solve the problem of this!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…