B4J Question JavaObject to Image View

nazilabdulla

Member
Licensed User
Longtime User
B4X:
Private Webcam,ImageIO,BufferedImage,FileIO,Dimension As JavaObject
Public Sub TakePicture(cam As JavaObject,filename As String)
    FileIO=    FileIO.InitializeNewInstance("java.io.File",Array(filename))
    BufferedImage=cam.RunMethod("getImage",Null)
    ImageIO.RunMethod("write",Array(BufferedImage, "PNG", FileIO))
    
    
    
    Log("Close: "&cam.RunMethod("close",Null))
End Sub


How can this image view in ImageView ?
 

drgottjr

Expert
Licensed User
Longtime User
if your write() method is successful, then you have the image file (whatever "filename" points to).
you load that into an imageview:
XUI:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private xui As XUI '<-------------
   Private ImageView1 As ImageView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1")
   MainForm.Show
   Dim bmp As B4XBitmap = xui.LoadBitmap(File.DirAssets, "image.png")
   FillImageToView(bmp, ImageView1)
End Sub

there used to be a "B4J" way and a "B4A" way. then it was decided to make all the "B4*" stuff cross-platform: XUI. so you have to include a reference to the XUI library in your project. it's supposed to let us use 1 set of calls across the B4X platforms. i have no doubt it does.

i only know (understand and use) the old B4A way. i couldn't find an example for the old B4J way for you. the authorities really want us to use XUI. i found the example above. i'm sure there are many more, but i got tired looking for you. search for imageview b4j or imageview xui.

if your write() method was not successful, then you need to make it successful before you can try the above.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top