Was working on flipping images so I could show mirrored/reflected images correctly (and in a readable way). Tried and hoping that using the FlipCompressedBitmap method from the BitmapCreator library could help me out but I couldn't get it to work (nor understand it). Will need need to study the BitmapCreator tutorials/samples more before using it.
However, I was able to solve my problem by working directly on the ImageView itself as you can see in below screenshots.
Maybe it can be useful for others too so I am sharing the code here:
I am also attaching it as a B4J project.
However, I was able to solve my problem by working directly on the ImageView itself as you can see in below screenshots.
Maybe it can be useful for others too so I am sharing the code here:
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private btnFlip As Button
Private imv1 As ImageView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
Dim bmp As Image = fx.LoadImage(File.DirAssets,"testmirror.jpg")
imv1.SetImage(bmp)
MainForm.Title = "B4J Flip ImageView"
MainForm.Show
End Sub
Sub btnFlip_Click
If btnFlip.Text = "Undo" Then
UndoFlipImageView(imv1)
btnFlip.Text = "Flip"
Else
FlipImageView(imv1,"Horizontal")
btnFlip.Text = "Undo"
End If
End Sub
Sub FlipImageView(imv As ImageView, Direction As String)
Dim joImv As JavaObject = imv
Dim joRotate As JavaObject
joRotate.InitializeNewInstance("javafx.scene.transform.Rotate",Null)
Dim joBounds As JavaObject = joImv.RunMethod("getBoundsInLocal",Null)
Dim bW As Double = joBounds.RunMethod("getWidth",Null)/2.0
joImv.RunMethod("setTranslateZ",Array(bW))
If Direction = "Horizontal" Then
joImv.RunMethod("setRotationAxis",Array(joRotate.GetField("Y_AXIS")))
Else if Direction = "Vertical" Then
joImv.RunMethod("setRotationAxis",Array(joRotate.GetField("X_AXIS")))
End If
joImv.RunMethod("setRotate",Array(180.00))
End Sub
Sub UndoFlipImageView(imv As ImageView)
Dim joImv As JavaObject = imv
Dim joRotate As JavaObject
joRotate.InitializeNewInstance("javafx.scene.transform.Rotate",Null)
joImv.RunMethod("setRotate",Array(0.00))
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
I am also attaching it as a B4J project.
Attachments
Last edited: