B4J Question B4J Load large image into ImageView

js486dog

Active Member
Licensed User
Longtime User
I have used the code below to open jpg image.

There is no problem to open not large image.

But I can not open (load into ImageView) large image (w:7800, h:7400).

Please is there a way to load large image into ImageView with B4J ?

My code:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private Button1 As Button
    Dim directory, fileName As String
    Private ImageView1 As ImageView
    Private P_imag As Pane
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
End Sub

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Button1_Click
    Dim fc As FileChooser
    fc.Initialize
    fc.InitialDirectory = File.DirApp
    fc.SetExtensionFilter("Layouts",Array("*.jpg"))
    fc.Title = "photo"
    
    Dim f As String = fc.ShowOpen(MainForm)
    directory = File.GetFileParent(f)
    fileName = File.GetName(f)
    Dim bmp As Image = fx.LoadImage(directory,fileName)

    If f <> "" Then
        
        ImageView1.SetImage(bmp)
        ImageView1.SetSize(bmp.Width, bmp.Height)
    End If
End Sub
 

emexes

Expert
Licensed User
perhaps this:

1594465334191.png
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Could it be what you are looking for?

 
Upvote 0

emexes

Expert
Licensed User
I gave big images a go here, tried creating larger and larger ones until something broke:

1594469452933.png


18600 x 18600 x 24 bit color = at least 1,037,880,000 bytes, or perhaps one-third more if is RGBA.

Then I looked to see if the Java heap could be made larger, and sure enough somebody suggested giving #VirtualMachineArgs a burl:

1594469598946.png


so I did, and that was the last I heard from my computer for about 8 minutes. It sank to its knees and I was starting to worry.

Anyway, when it blinked I managed to capture this:

1594469737507.png

and then when it properly regained consciousness I had this:

1594469874220.png


both of which suggest that the maximum object size, for the JVM on my machine at least, is limited by the maximum value of Java's default signed 32-bit Integer, so the maximum image size would be like 23000 RGBA pixels square.
 
Last edited:
Upvote 0

js486dog

Active Member
Licensed User
Longtime User
Could it be what you are looking for?

Thank you very much for the answer.
ZoomImageView is fine.
I can work with large images, but I miss "EventData" (at least MouseMoved).

Classic ImageView has "EventData" (MouseMoved, MouseDragged ...).
B4X:
Sub ImageView1_MouseMoved (EventData As MouseEvent)
    L_xsur_pix = EventData.X
    L_ysur_pix = EventData.Y
End Sub
 
Upvote 0

js486dog

Active Member
Licensed User
Longtime User
If you need to handle larger images outside of ZoomImageView, perhaps try increasing the Java heap size using #VirtualMachineArgs attribute:

View attachment 96968

Use G for gigabytes or M for megabytes.
Thank you very much.
B4X:
#VirtualMachineArgs: -Xms1024m -Xmx1024m
is fine when I start app from B4J IDE.

But after compilation jar to exe (Launch4j) still works only:
bmp.Resize(400, 300, True)
not
bmp.Resize(7800, 7400, True)
 
Upvote 0

js486dog

Active Member
Licensed User
Longtime User
Thank you very much.
B4X:
#VirtualMachineArgs: -Xms1024m -Xmx1024m
is fine when I start app from B4J IDE.

But after compilation jar to exe (Launch4j) still works only:
bmp.Resize(400, 300, True)
not
bmp.Resize(7800, 7400, True)
It seems here is the solution.
Have to be set "heap size" in "Launch4j" to 1024 or another number.
Now exe file works as B4J IDE - also with large image .
sets_jre.jpg
 
Upvote 0
Top