B4J Question Trouble writing text to image

warayTek

Member
Licensed User
Hi, I am not sure why the following code is not working. I'm calling a second form.
Screenshot 2023-09-19 152605.png

The code below is what I'm using when the form is called.
B4X:
Dim newForm As Form
    newForm.Initialize("digiSignForm",530,380)
    newForm.Resizable = False
    newForm.RootPane.LoadLayout("MainPage")
    newForm.ShowAndWait
    pnDraw = xui.CreatePanel("")
    '
    'MainForm.AddView(pnDraw, ImageView1.Left, ImageView1.Top,ImageView1.Width, ImageView1.Height)
    Log(ImageView1.Width & " " & ImageView1.Height)
    mCanvas.Initialize(pnDraw)
    mRect.Initialize(0, 0, ImageView1.Width, ImageView1.Height)
    mCanvas.DrawBitmap(ImageView1.Snapshot, mRect)

And in the "Write" button this is the code.
B4X:
mCanvas.ClearRect(mCanvas.TargetRect)
mCanvas.DrawBitmap(ImageView1.Snapshot, mRect)
mCanvas.DrawText(TextField1.Text, 5, 24, xui.CreateDefaultFont(22), xui.Color_Black, "LEFT")
 

Attachments

  • Screenshot 2023-09-19 152605.png
    Screenshot 2023-09-19 152605.png
    40.5 KB · Views: 36

DonManfred

Expert
Licensed User
Longtime User
Hi @klaus, I am not able to write text to the image. Please see the attached file.
The function I'm trying to work on is on "SECOND form" button.
Where is the testproject we can try?
Without seeing what you have done and how it is impossible to give any congrete Advice.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I had a look at your project.
The main problem was this line:
newForm.ShowAndWait
From the help :
1695128059845.png

The current code is stopped...

I made some changes in your code to show the drawing.
I replaced newForm.ShowAndWait by newForm.Show.
Instead of adding pnlDraw in the code, i added it to your MainPage layout.
I do not use the ImageView1 but load the digSig2.png image as a B4XBitmap and draw this one instead of ImageView1.Snapshot.

You tryed to add pnlDraw to MainForm with this line which will not work:
MainForm.AddView(pnDraw, ImageView1.Left, ImageView1.Top,ImageView1.Width, ImageView1.Height)
It should have been B4J specific:
MainForm.RootPane.AddNode(pnDraw, ImageView1.Left, ImageView1.Top,ImageView1.Width, ImageView1.Height)

Attached the modified project.

I would suggest you to switch to B4XPages, which will make the use of different forms much easier.
And another advice, use as much as possible B4XViews instead of platform specific objects, even for single platform projects.
B4XViews have some more properties than platform specific objects.
 

Attachments

  • ShowPDFinB4J1.zip
    383.7 KB · Views: 50
Upvote 0
Top