Help with canvas on Windows

I am updating an old application from RB2006 to Xojo 2014 and I am having problems with a canvas area. Xojo says that Graphics is deprecated and I should use Paint instead. So I have been working on making changes, but I am having problems making this work cross platform.

I have a canvas area where I display a picture and the intent is to allow the user to draw on top of it in a separate layer. The user markup is saved separately, I don’t want to save the original image and the markup. On the Mac I have this close to working, but on Windows the draw picture does not display.

The old version of the application created two pictures, one for the background picture and one for the drawing. Then the paint event on the canvas would draw the two pictures, first the background picture and then the draw layer. For Windows, the application used a buffer picture to draw into. When a draw tool was used the Mac app would draw into the draw layer, the Windows app drew into the buffer picture.

I started by removing the buffer picture on Windows and figured I could just draw into the same picture like I do for the Mac. When I debug I can see the drawing changes on the draw picture, but it never displays on the canvas. All that displays is the background picture. Pictures are created like this:

mBackgroundLayer = New Picture(me.Width, me.Height, 32)
mModLayer = New Picture(me.Width, me.Height, 32)

Is it possible to layer pictures on Windows?
Would it be better to put my background picture into the background property of the canvas? (Works without doing this on Mac.)

I have just returned to using Xojo so have not kept up with changes over the years. From looking at example apps it looks like I don’t need to draw into a buffer for the Windows version of the app. (I don’t remember why it was necessary 8 years ago, but that is the way it was written.) I haven’t found exactly what I need yet in any of the user guides or forum posts. So any pointers on where to look to figure out how to make this work would be appreciated.

Note: Use GDI Plus is turned on for Windows.


what happens if you leave out the 32?

I can’t leave out the 32 because I set the mod layer transparent:

mModLayer.Transparent = 1

This was done so the background picture layer would show through.

Oh, I don’t use the .Transparent. I just use
Dim p As New Picture(width, height)
Which gives me a transparent picture and draw onto it what I need.

[quote=127881:@Jym Morton]Oh, I don’t use the .Transparent. I just use
Dim p As New Picture(width, height)
Which gives me a transparent picture and draw onto it what I need.[/quote]

It works fine on the Mac. In Windows, GDI+ has to be enabled otherwise it generates an error.

Yes, because transparency using Alpha is a GDI+ thing :slight_smile:

This is solved now.

I tried again creating the pictures without the 32 for depth, but this time removed the line setting Transparent to 1. So now both pictures do show.

The documentation led me to believe that I could use the bit depth to obtain the transparency. But that doesn’t work on Windows. Leaving it out creates the image with an alpha channel, as commented about above, and as long as I leave out the Transparent setting it does work on Windows.

It’s either 32 bits+transparent, or alpha channel. Alpha Channel is the preferred way to go.