Canvas vs Image

Just starting out? Need help? Post your questions and find answers here.
barryem
User
User
Posts: 19
Joined: Mon Jan 27, 2014 2:40 am

Canvas vs Image

Post by barryem »

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
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Canvas vs Image

Post by Little John »

Two main differences are:
Last edited by Little John on Sun Jun 19, 2016 10:12 pm, edited 1 time in total.
barryem
User
User
Posts: 19
Joined: Mon Jan 27, 2014 2:40 am

Re: Canvas vs Image

Post by barryem »

Thank you! That helps a lot.

Barry
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Canvas vs Image

Post by davido »

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?

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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Canvas vs Image

Post by netmaestro »

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
barryem
User
User
Posts: 19
Joined: Mon Jan 27, 2014 2:40 am

Re: Canvas vs Image

Post by barryem »

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
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Canvas vs Image

Post by davido »

@netmaestro,
Thank you for the explanation, I now understand. :)
DE AA EB
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Canvas vs Image

Post by Little John »

Hi davido,

what can I say? Netmaestro was faster. :-)
barryem
User
User
Posts: 19
Joined: Mon Jan 27, 2014 2:40 am

Re: Canvas vs Image

Post by barryem »

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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Canvas vs Image

Post by netmaestro »

SetGadgetAttribute(#Canvas, #PB_Canvas_Image, ImageID(-image#-))
BERESHEIT
barryem
User
User
Posts: 19
Joined: Mon Jan 27, 2014 2:40 am

Re: Canvas vs Image

Post by barryem »

Thank you!

Barry
Post Reply