B4J Question Canvas to Image is not showing the Lines

Swissmade

Well-Known Member
Licensed User
Longtime User
Hi all,

I have a Canvas where I draw some lines on it.
When I save the Snapshot to a file I get nicely the Lines.
Code Snipper.
B4X:
  img = cvs.Snapshot
  Dim Out As OutputStream
  Out = File.OpenOutput("c:\","Hello" & x1 & ".png",False)
  img.WriteToStream(Out)
  Out.Close
'Here I get the Drawing Lines from the cvs.Snapshot in a file
  gxIMG.SetImage(img)
'When I do this directly I don't See any line.
I don't need the file I like to have the Lines directly in the Image.
Saving the Image and Load again is no option because of performance.
Maybe some Refresh issues??
Hope anybody can help.
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
Does the image that you saved have the correct dimensions, I seem to recall a problem with images ending up at 1 x 1 pixel, but can't remember if it was related to canvas snapshots.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've tried this code and it works:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private cvs As Canvas
   Private iv As ImageView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.Show
   cvs.Initialize("csv")
   MainForm.RootPane.AddNode(cvs, 0, 0, 100, 100)
   cvs.DrawCircle(50, 50, 20, fx.Colors.Red, True, 0)
   iv.Initialize("iv")
   MainForm.RootPane.AddNode(iv, 0, 100, 100, 100)
   iv.SetImage(cvs.Snapshot)
End Sub
You will see two red circles.
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Does the image that you saved have the correct dimensions, I seem to recall a problem with images ending up at 1 x 1 pixel, but can't remember if it was related to canvas snapshots.

Yes the Image has the same dimension.
:)
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Hi Erel,
After your code has the same issue, I go to debug this and I found the problem.
The Event what is giving me the coordinates for the line is fired two times.
First with the coordinates where I see the lines and second without so the line is go away.
Happy to see that this is the problem and I can fix this.

To Explain what I'm doing.
I have build a library in Java to read License Plates. The Library build around a ANPR SDK I use already for about 10 Years.
The old Application I try to replace is written in VB6.
Working very fast and precisely.

After a plate is found, there will be all the coordinates to draw the line around the Plate.
Erel I think this is the first Application for ANPR in B4J
;)


Many thanks for all your help in this.
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
It is not a error or bug the Library is doing what I ask.
I can read more then one plate on a Image so when the second read has not a second plate , I get the Image and zero coordinates back.

In the meantime its solved. just one boolean and its working fast with Lines.;););)
 
Upvote 0
Top