GetGadgetAttribute(#canvas, #PB_Canvas_Imag

Just starting out? Need help? Post your questions and find answers here.
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

GetGadgetAttribute(#canvas, #PB_Canvas_Imag

Post by akj »

I wish to take the image from a canvas gadget, crop it, save it as a separate image and eventually print it.
My code [within a much longer program] is something like this:

Code: Select all

#canvas = 1
StartDrawing(PrinterOutput())
  imageID = GetGadgetAttribute(#canvas, #PB_Canvas_Image) ; #canvas is the gadget number for my canvas gadget
  imageCropped = GrabImage(image, #PB_Any, 200, 250, 20, 25) ; Last 4 numbers define the cropping area
  DrawImage(ImageID(imageCropped), 0, 0)
StopDrawing()
The trouble is that GetGadgetAttribute() returns an image ID but GrabImage() requires an image number. Thus I need the inverse of the ImageID() function, which I would have thought was impossible. How should I proceed?
Anthony Jordan
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4972
Joined: Sun Apr 12, 2009 6:27 am

Re: GetGadgetAttribute(#canvas, #PB_Canvas_Imag

Post by RASHAD »

Hi
Use instead
Result = GrabDrawingImage(#Image, x, y, Width, Height)

But
This command does Not work With PrinterOutput().

Code: Select all

#canvas = 1
#image = 10
StartDrawing(CanvasOutput(#canvas))
  GrabDrawingImage(#image,200, 250, 20, 25)
StopDrawing()

StartDrawing(PrinterOutput())
  DrawImage(ImageID(#image), 0, 0)
StopDrawing()

SaveImage(#image,GetHomeDirectory()+"Test.bmp")

Egypt my love
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Re: GetGadgetAttribute(#canvas, #PB_Canvas_Imag

Post by akj »

Thank you Rashad for your very helpful answer, which works.
Anthony Jordan
Post Reply