Erase Drawstring (ImageLibEx)

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
how can I delete the text previously written with Drawer.DrawString1 (String, SolidBrush.Value, x, y)?
Of course I use ImagelibEx library of Agraham.
 

mjcoon

Well-Known Member
Licensed User
Draw the same text with the background color.

Best regards.

Which of course can only work if the area concerned was occupied solely by the background colour before the text was drawn!

Otherwise it would be necessary to save the area involved and re-instate it (somehow...).

Mike.
 

micro

Well-Known Member
Licensed User
Longtime User
The DrawString1 is used on the image con gradientfill, how i can save the area before and after recall?
 

klaus

Expert
Licensed User
Longtime User
You should define the rectangle occupied by the string before drawing it.
With the x and y coordinates, Drawer.StringHeight and Drawer.StringWidth.
Copy the string background part to a bitmap.
To erase the string copy back the saved background part of the screen.

Best regards.
 

micro

Well-Known Member
Licensed User
Longtime User
I'm sorry Klaus, but it does not work :eek:
you can give me an example?
B4X:
................
drawer.nfont.New1("", 20, 1)
   drawer.nfont.Name = "Arial"
   drawer.drwstr.Font = drawer.nfont.Value
   str = "Prova"
   drawer.Sbrush.Color = cBlack
   ''''save
   drawer.bmp.New2(drawer.drwstr.StringHeight(str), drawer.drwstr.StringWidth(str))
   drawer.Rectsave.New1(48, 48, drawer.drwstr.StringHeight(str) + 1, drawer.drwstr.StringWidth(str) + 1)
   drawer.bmp.ScreenCapture(drawer.Rectsave.Value)
   ''''
drawer.Sbrush.Color = cBlack
   drawer.drwstr.DrawString1(str, drawer.Sbrush.Value, 50, 50)
   drawer.Sbrush.Color = cWhite
   drawer.drwstr.DrawString1(str, drawer.Sbrush.Value, 49, 49)
........
........
'restore
drawer.drwstr.DrawImage(drawer.bmp.Value, drawer.Rectsave.Value, drawer.Rectsave.Value, True)
   Form1.Refresh
 

mjcoon

Well-Known Member
Licensed User
You should define the rectangle occupied by the string before drawing it.
With the x and y coordinates, Drawer.StringHeight and Drawer.StringWidth.
Copy the string background part to a bitmap.
To erase the string copy back the saved background part of the screen.

Best regards.

I have a background info query. I haven't done fancy string drawing in B4PPC. But I recollect that in general the reference starting point of a string is the base line; most of the text is above but descenders are below. Is this how it works in B4PPC, or is the reference at lowest descender height or highest point of ascenders? Unless it is one of those latter, Drawer.StringHeight would not be enough information to define the enclsoing rectangle.

TIA, Mike.
 

klaus

Expert
Licensed User
Longtime User
Attached you find a small demo program.
I leave it up to you to adapt it to your needs.
If you want to erase more than the last text drawn you should use arrays to memorise the rectangles and background images.

Best regards.
 

Attachments

  • DrawText.zip
    57.3 KB · Views: 328

mjcoon

Well-Known Member
Licensed User
Attached you find a small demo program.

I got a crash when I clicked the "Erase" button (see attachment).

Mike.

(Ah, I see it just assumes that there has been a mouse-down.)
 

Attachments

  • error.PNG
    error.PNG
    10.9 KB · Views: 328
Last edited:
Top