I have a custom class descended from a panel that I'm using to display
diagrams. I'd like to provide the user with a way to save the current
diagram as a bitmap, or copy it to the clipboard. Any thoughts on
getting a bitmap representation of the panel's DC? Thanks.
Nathan
See the Wiki WorkingWithImages topic (screen capture sub-topic):
http://wiki.wxpython.org/index.cgi/WorkingWithImages#line106
You could also use a MemoryDC and explicitly call your renderer if you want, for instance, to have the ability to copy an area larger than the screen.
HTH,
Mike
Nathan R. Yergler wrote:
···
I have a custom class descended from a panel that I'm using to display
diagrams. I'd like to provide the user with a way to save the current
diagram as a bitmap, or copy it to the clipboard. Any thoughts on
getting a bitmap representation of the panel's DC? Thanks.
Nathan
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users
--
_______________________________________
Mike C. Fletcher
http://members.rogers.com/mcfletch/
Nathan R. Yergler wrote:
I have a custom class descended from a panel that I'm using to display
diagrams. I'd like to provide the user with a way to save the current
diagram as a bitmap, or copy it to the clipboard. Any thoughts on
getting a bitmap representation of the panel's DC? Thanks.
Nathan
Alternatively, you can use the ImageDraw module of PIL (additionnal library). Of course you have to re-write code for drawing diagram.
http://www.pythonware.com/products/pil/index.htm
*Example: Draw a Grey Cross Over an Image*
import Image, ImageDraw
im = Image.open("lena.pgm")
draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line((0, im.size[1], im.size[0], 0), fill=128)
del draw
# write to stdout
im.save(sys.stdout, "PNG")
Maybe there's a better solution. But I have a snippet of code that uses a
wxMemoryDC that paints into an existing bitmap template. It may help you,
if you need to go the ugly way of using a seperate wxMemoryDC to get the
job done.
def create(self):
wxImage_AddHandler( wxPNGHandler() )
dc = wxMemoryDC()
dc.SetFont( self.font )
if self.infile == None:
bmp = wxEmptyBitmap(self.width, self.height, self.colordepth)
else:
bmp = wxBitmap(self.infile, wxBITMAP_TYPE_PNG)
dc.SelectObject(bmp)
dc.DrawText(self.text, 5, 4)
img = wxImageFromBitmap(bmp)
img.SaveFile(self.outfile, wxBITMAP_TYPE_PNG)
Gerhard
···
"Nathan R. Yergler" <nyergler@mac.com> wrote:
I have a custom class descended from a panel that I'm using to display
diagrams. I'd like to provide the user with a way to save the current
diagram as a bitmap, or copy it to the clipboard. Any thoughts on getting a
bitmap representation of the panel's DC? Thanks.
--
mail: gerhard.haering@gmx.de registered Linux user #64239
web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))
Thanks. I hadn't thought of the MemoryDC. My drawing handler already
takes a generic DC so I can use it for printing and on-screen display;
extending it to work with a generic bitmap shouldn't be too difficult.
Nathan
···
On Tue, 2002-07-02 at 00:56, Mike C. Fletcher wrote:
See the Wiki WorkingWithImages topic (screen capture sub-topic):
http://wiki.wxpython.org/index.cgi/WorkingWithImages#line106
You could also use a MemoryDC and explicitly call your renderer if you
want, for instance, to have the ability to copy an area larger than the
screen.
HTH,
Mike
Nathan R. Yergler wrote:
> I have a custom class descended from a panel that I'm using to display
> diagrams. I'd like to provide the user with a way to save the current
> diagram as a bitmap, or copy it to the clipboard. Any thoughts on
> getting a bitmap representation of the panel's DC? Thanks.
>
> Nathan
>
>
>
>
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwindows.org
> http://lists.wxwindows.org/mailman/listinfo/wxpython-users
>
--
_______________________________________
Mike C. Fletcher
http://members.rogers.com/mcfletch/
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users