Here's an approach I used before:
- Move the code that paints your canvas from its Paint event into a separate
method like this:
Sub Redraw(g As Graphics = nil)
dim OtherDest as Boolean
if g = nil then
// we're drawing to the Canvas
g = MyCanvas.Graphics
else
// we're drawing to something else
OtherDest = true
end if
// Double buffer the Graphics
dim g1 as Graphics
dim p as Picture
if OtherDest then
g1 = g
else
p = NewPicture(CircuitWidth, CircuitHeight, 32)
g1 = p.Graphics
end if
// Now paint all your stuff using the g1 grapics object
// .......
if not OtherDest then
// Draw circuit to canvas
g.DrawPicture p, ScrollXPos, ScrollYPos
end if
End Sub
- From the Canvas' paint event, just call Redraw without passing an
argument, and the Canvas contents will be drawn as before.
- To take a screenshot, create a picture that has the same width and height
as the Canvas and call Redraw and pass the picture's graphics object:
dim p as new Picture(MyCanvas.Width, MyCanvas.Height, 32)
Redraw(p.Graphics)
- Now you have the Canvas contents in p.
This also works if you want to print the Canvas contents. Simply pass the
graphics object returned by OpenPrinterDialog to Redraw.
Roger
> From: Christian Miller <[EMAIL PROTECTED]>
> Reply-To: REALbasic NUG <[email protected]>
> Date: Sat, 15 Jul 2006 09:34:36 -0400
> To: REALbasic NUG <[email protected]>
> Subject: Graphics object to Picture?
>
> Is it possible to obtain the contents of a canvas and place it back
> into a Picture object? Sort of the opposite of double-buffering.
> Without knowing what has been drawn on the canvas, I want to take a
> "snapshot" of what the canvas few. I hope that makes sense, I don't
> feel like I'm explaining myself correctly.
>
>
> Christian
> Pariahware, Inc. Custom Software
> <[EMAIL PROTECTED]>
> <http://www.pariahware.com>
> --
> God loved you so much that He gave His only son Jesus. What have you
> done with God's gift?
>
>
>
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
>
> Search the archives of this list here:
> <http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>