[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WebDrawingArea to Image


Hi Bruce,
Thank you for pointing me to a direction.
After few searches I finally reach the same command you mentioned.

I will post the piece of code in _javascript_ that I used because it works very well in my case.

Thanks
Olivier 

Le 15 juil. 2026 à 03:49, Bruce Steers <bsteers4@xxxxxxxxx> a écrit :


Ps.  it would probably be best to use your initial idea and "snapshot" the ready drawn canvas image using GetImageData.

All other options are probably going to be pretty complicated.

Respects
BruceS 

On Tue, 14 Jul 2026, 21:04 Bruce Steers, <bsteers4@xxxxxxxxx> wrote:
There is a _javascript_ function in html canvas API , GetImageData

There is nothing like that built in to the WebDrawingArea though but you should be able to use _javascript_ for the canvas api.

Respects
BruceS

On Tue, 14 Jul 2026 at 18:44, Olivier Cruilles <olivier.cruilles@xxxxxxxx> wrote:
In fact I would like to get all the <canvas><script>…</script></canvas> code produced sent to the Web Browser in the way to inject it into an <iframe></iframe> balise that will be used by the Web Browser to Print it.

I’m already doing that for any html page I want to print by the Web Browser but I don’t find a way to catch the WebDrawingArea html+_javascript_ code sent to the Browser by Gambas.

Any idea


Olivier

Le 14 juill. 2026 à 11:21, Olivier Cruilles <olivier.cruilles@xxxxxxxx> a écrit :

Hello,


I would like to create an Image file from the drawing commands I use into a WebDrawingArea object, like we can do it for DrawingArea object.
It is possible to do it like that ?

Public Sub Create_Image()

  Dim hImg As New Image(Paint.Width, Paint.Height, Color.White, Image.Standard)

  Htmldata = WebDrawingAreaCourbe.ToHTML()

  Paint.Begin(hImg)
  Paint.Scale(1, 1)

    'Exemple of code to draw
    Paint.LineWidth = 1

    Paint.Rectangle(50, 50, 150, 150)
    Paint.Stroke(Color.Red, True)
    Paint.Fill(Color.SetAlpha(Color.SoftBlue, 192))

    Paint.Rectangle(80, 80, 150, 150)
    Paint.Stroke(Color.SetAlpha(Color.Yellow, 64))

    Paint.Arc(100, 100, 60)
    Paint.Fill(Color.Red)
    Paint.Rectangle(20, 20, 120, 70)
    Paint.Fill(Color.SetAlpha(Color.Royal, 64))

    Paint.Ellipse(20, 20, 120, 70, 0, -Pi / 2)
    Paint.Stroke(Color.Green)

    Paint.Rectangle(40, 80, 120, 70)
    Paint.Brush = Paint.LinearGradient(80, 140, 100, 120, [Color.Red, Color.Green, Color.Violet], [0, 0.5, 1])
    Paint.Fill()

    Paint.Rectangle(60, 90, 120, 70)
    Paint.Brush = Paint.LinearGradient(220, 200, 340, 200, [Color.Red, Color.Green, Color.Violet], [0, 0.5, 1])
    Paint.Fill()

    Paint.Arc(100, 320, 40)
    Paint.Brush = Paint.RadialGradient(100, 320, 2, 100, 320, 40, ["red", "yellow", "lightblue"], [0, 0.6, 1])
    Paint.Fill()

  Paint.End()

  Try hImg.Save("/tmp/imagecourbe.png")
  If Error Then
    ModLogs.EcrireLogs("Error during image saving ! - Error: " & Error.Text)
  Endif

End

I know it's possible with Cairo library too, but through gb.gui.web component I not sure.

Any idea ?

Thank you

-- Olivier




References:
Re: WebDrawingArea to ImageBruce Steers <bsteers4@xxxxxxxxx>