Canvas vs Image
Canvas vs Image
I'm a little confused about when to use an Image gadget and when to use a Canvas gadget. Could someone discuss their differences a bit? And the different ways they might be used?
For example, I'm making a little drawing program as a way to learn a bit about graphics in PB and I'm using a canvas for the drawing area. Actually that code came from the sample included with PB. Then I used another canvas for the palette. I began wondering if there was any reason I should have used an image gadget instead. It does have to deal with both left and right mouse cllicks and will probably deal with gradients and alpha down the road as I learn more about this.
Any discussion or tips are appreciated. By the way I'm hoping for some discussion about this and not a simple answer about which to use, although that might be nice too. This isn't a problem I'm trying to solve. I just want to undestand it more.
Barry
For example, I'm making a little drawing program as a way to learn a bit about graphics in PB and I'm using a canvas for the drawing area. Actually that code came from the sample included with PB. Then I used another canvas for the palette. I began wondering if there was any reason I should have used an image gadget instead. It does have to deal with both left and right mouse cllicks and will probably deal with gradients and alpha down the road as I learn more about this.
Any discussion or tips are appreciated. By the way I'm hoping for some discussion about this and not a simple answer about which to use, although that might be nice too. This isn't a problem I'm trying to solve. I just want to undestand it more.
Barry
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Canvas vs Image
Two main differences are:
- The CanvasGadget supports more events than the ImageGadget.
- in contrast to the ImageGadget, the CanvasGadget has no Alpha channel.
Last edited by Little John on Sun Jun 19, 2016 10:12 pm, edited 1 time in total.
Re: Canvas vs Image
Thank you! That helps a lot.
Barry
Barry
Re: Canvas vs Image
Hi Little John,
I always thought that the CanvasGadget did not support the Alpha channel.
However, the demo code from RotateCoordinates from the VectorDrawing Library, appears to contradict that as it clearly shows the Alpha channel working.
What am I missing?
I always thought that the CanvasGadget did not support the Alpha channel.
However, the demo code from RotateCoordinates from the VectorDrawing Library, appears to contradict that as it clearly shows the Alpha channel working.
What am I missing?
Code: Select all
If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 400, 200)
If StartVectorDrawing(CanvasVectorOutput(0))
VectorFont(LoadFont(0, "Times New Roman", 60, #PB_Font_Bold))
VectorSourceColor(RGBA(0, 0, 255, 128))
MovePathCursor(50, 50)
DrawVectorText("Test")
ScaleCoordinates(0.7, 0.9)
VectorSourceColor(RGBA(255, 0, 0, 128))
MovePathCursor(50, 50)
DrawVectorText("Test")
StopVectorDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
DE AA EB
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Canvas vs Image
No. An image of any depth can accept the results of alphablended output. If the canvasgadget actually did support the alpha channel then the canvas background would be the same as the window background with this code:
Code: Select all
If OpenWindow(0, 0, 0, 600, 400, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0, RGB(255,0,255))
CanvasGadget(0, 0, 0, 400, 200)
If StartVectorDrawing(CanvasVectorOutput(0))
VectorFont(LoadFont(0, "Times New Roman", 60, #PB_Font_Bold))
VectorSourceColor(RGBA(0, 0, 255, 128))
MovePathCursor(50, 50)
DrawVectorText("Test")
ScaleCoordinates(0.7, 0.9)
VectorSourceColor(RGBA(255, 0, 0, 128))
MovePathCursor(50, 50)
DrawVectorText("Test")
StopVectorDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
BERESHEIT
Re: Canvas vs Image
I had no idea about the vector drawing library. Thanks for calling my attention to it. I just might have some fun with that. 
Barry

Barry
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Canvas vs Image
I'm playing with doing things on imagegadgets and canvasgadgets and I don't see any obvious way to copy an image to a canvas. Is there a way to do that?
Thanks,
Barry
Thanks,
Barry
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada