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


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

'B4a code

Dim bmp As Bitmap
Dim rbmp As RSImageProcessing

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


Well-Known Member
Licensed 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

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)
End Sub


Active Member
Licensed User
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!


Active Member
Licensed 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!


Active Member
Licensed 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
      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!
Seems impossible to solve the problem of this!