Migrate from 2015 to 2019: Graphics

Hello XOJO Guru’s,

I have a small Question About the Graphics Property from a Canvas. We’ve been using an Pretty old XOJO Version, somewhere in the range of the 2015 Edition. Since then a lot has changed and I felt it was worth an upgrade. We’d like to do this but there is a Problem. In newer versions the Graphics Property is not available anymore.

I saw this blogpost XOJO published and there is so much “easy talk”. But there is a Problem. We have actual data to get which is being painted. I can’t place this in the paint Event, since it is conditionally. How can I convert the following Code to work with the latest Version? How can I trigger the Paint Event from a totally seperated class?

[code]Dim SignatureImage as String
SignatureImage = “https://thisisapathhowthecodelooks.local/” + DefineEncoding (rs.Field (“path”).StringValue, Encodings.UTF8)

Dim https As New HTTPSecureSocket
https.Secure = True
https.ConnectionType = SSLSocket.TLSv12
Dim data As MemoryBlock = https.Get(SignatureImage, 5)

Dim newPic As New Picture(157, 75)
wndHauptFenster.SignatureImager.graphics.DrawPicture(Picture.FromData(data), 0, 0, newPic.width, newPic.height, 0, 0, Picture.FromData(data).width, Picture.FromData(data).height)
[/code]

Greetings and stay safe,

You could simply draw on a picture you set as backdrop. It would be much simpler than refactoring to use the Paint event handler.

Something like:

Dim Mybackdrop as new picture(SignatureImager.width, SignatureImager.height) SignatureImager.backdrop = MyBackdrop Dim newPic As New Picture(157, 75) SignatureImager.Backdrop.graphics.DrawPicture(Picture.FromData(data), 0, 0, newPic.width, newPic.height, 0, 0, Picture.FromData(data).width, Picture.FromData(data).height)

Thanks! That was exactly what I was Looking for!

You trigger the Paint event by calling Invalidate() or Refresh().

It looks like you can split up the two parts.

  1. The first part gets the image from the web service. You can store that data in a property somewhere.

  2. The second part draws the image from the data. Provide the data to the window that contains the Canvas (perhaps as a property), call Canvas.Invalidate and in the Canvas.Paint event have the Canvas use this property to draw the picture.

So for this code:

Dim newPic As New Picture(157, 75) wndHauptFenster.SignatureImager.graphics.DrawPicture(Picture.FromData(data), 0, 0, newPic.width, newPic.height, 0, 0, Picture.FromData(data).width, Picture.FromData(data).height)

you would want to do something like this:

  1. Add PicData As Picture property to wndHauptFenster.
  2. On wndHauptFenster.SignatureImager (which I presume is a Canvas), draw the PicData in the Paint event:

If PicData <> Nil Then g.DrawPicture(PicData, 0, 0, 157, 75, 0, 0, PicData.Width, PicData.Height) // Not sure about 157, 75 values. If that's size of Canvas, then use g.Width/g.Height instead End If

Now you can remove your original code that draws the picture and instead set the property and tell the Canvas to redraw:

wndHauptFenster.PicData = Picture.FromData(data) Picture.FromData(data).SignatureImager.Invalidate(False)

I’d probably combine those two lines of code into a method or computed property on wndHauptFenster and call it.