WebCanvas DrawPicture

Hello, I am working on a Web project for a scada system. The user chooses the type of sensor that they want to view and a WebDialog opens in the window for those sensors. They can then double-click a particular sensor that is on the listbox in that WebDialog to get a detailed view of just that sensor. The detailed view is another WebDialog. Both of these WebDialogs are Appearance type Palette. The Issue I can’t figure out is with WebCanvas on the detail view WebDialog. I am showing a RPM gauge that has the dial move depending on the pumps current rpm. I created the Image of the gauge and saved it as a png. Dragged it into the project. I am using a paint event to draw the image into the web canvas as well as the dial that moves. For some reason I can not get the g.DrawPicture(image, 0, 0) to display anything in the web canvas in a WebDialog, I copied the canvas and pasted it on a webpage and it displays fine with the same code. Does anyone have any ideas?

Indeed pictures don’t show in a webcanvas when placed on a palette.

The workaround I found is to place a WebIMageView as background, and place the WebCanvas over it. Note that oval and geometric drawing still work just fine.

In RubberViewsWE I had to deal with the same kind of phenomenon when the canvas was resized or moved, and I ended up drawing to a picture and displaying it in a WebImageView.

Hey Michel thank you for responding. I have been trying to draw to a picture and displaying it in a WebImageView for the past several hours to see if that would work. However I keep getting an error NilObjectException. In the WebDialog I have placed a WebImageView named ImageView 1 and in the open event of the Dialog I am setting the ImageViews .Picture to the Picture I want for the background. When the dialog receives a new RPM reading I have a method that determines the pixel location for the end of the draw line. After the endpoints are determined I am doing…
Dim p As New Picture(300, 300)
p = TanMarRPMGauge
p.graphics.ForeColor = &cff0000
p.graphics.PenWidth = 2
p.graphics.DrawLine(150,150, x, y)
ImageView1.Picture=p

The program breaks at ImageView1.Picture=p with a NilObjectException but if I select p in the debugger and view the contents it shows the picture exactly how i want it. If you have any suggestions I would truly appreciate it.

Don’t dim the picture. It will go out of scope at the end of the event. That is probably the reason for the nil object exception, as p no longer exist.

Instead, make P a property of the dialog or webpage, and do

p = New Picture(300, 300)

Created a property in the WebDialog for p as type picture and changed the event to what you suggested. Im still getting a NilObjectException

When I wrote “event” I actually meant method. Sorry

An event handler is a method too.

You must make sure NOT to dim p in the method. Otherwise you will still have the same issue because you are creating a variable local to the method.

p must be a property of the palette. Here is the corrected code :

p = New Picture(300, 300) p = TanMarRPMGauge p.graphics.ForeColor = &cff0000 p.graphics.PenWidth = 2 p.graphics.DrawLine(150,150, x, y) ImageView1.Picture=p

Note dim has been replaced by p = New Picture(300, 300)

Yes sir that is exactly how I have it. I even copied what you provided and pasted it in after deleting my own. p is a property with type picture. For some reason it keeps the program dies when it hits ImageView1.Picture=p
Exception — NilObjectException

Thank you for all the help your providing

Sigh…

https://dl.dropboxusercontent.com/u/17407375/p.xojo_binary_project

Im sorry for not being able to figure this out. If i move the code into the shown event handler as you have it in your test project then there is no NilObjectException. I was performing this in a method dialog that also determines where the endpoints for the drawline are. Is there a way to force the image to refresh as you can with canvas so that it will pull a new x and y for the drawline action.

Will one of you file a bug report about the WebCanvas on a Palette not drawing pictures?

45487 - Web : when a canvas is on a WebDialog (Palette, sheet or modal), it does not show pictures
Status: Needs Review Rank: Not Ranked Product: Xojo Category: N/A

Michel Bujardet Today at 10:41 AM
OS: OS X 10.12.1

Xojo: Xojo 2016r3

Steps: See attached project. The canvas does not display pictures with DrawPictures, whatever the type of the dialog.
File attached: picture.xojo_binary_project.zip

feedback://showreport?report_id=45487

Thx