Doodle to JPEG (or whatever)

Hi Mike,

Now I see you problem. I'm afraid I'm not really familiar with PIL beyond its basic capabilities. (No experience doing anything but tutorials with it) However, I have an idea: One approach that might work is to change doodle so that either it draws into a wxBitmap (see docs on wxMemoryDC) and then draws the bitmap to the visible window, or draws into the windowas it does now, but then repeats the same drawing command to a wxMemoryDC. You can convert a wxBitmap (device specific) to a wxImage (device independent) which has methods which can write it out to various standard image file formats.

I've never actually tried this, but the documentation implies it would work.

Hope that helps,
Barry

Mike Edmonds wrote:

···

Barry

Thanks, yes, I have had a look at that. It is the 'importing' that stumps
me, since the doodle doesn't start out life as a file, but rather a .. well,
um... a doodle. The format of a saved file (using superdoodle.py) is that of
a doodle (.ddl file) which PIL doesn't appear to support (and why should it,
I guess).

What I need to be able to do is use something like PIL to take a portion of
the screen and save it.

Can you point me to a PIL routine that might help?

Mike
----- Original Message ----- From: "Barry Tolnas" <tolnasb@evergreen.edu>
To: <wxPython-users@lists.wxwindows.org>
Sent: Monday, November 03, 2003 8:06 AM
Subject: Re: [wxPython-users] Doodle to JPEG (or whatever)

Mike Edmonds wrote:

As a newbie, can someone point me in the right direction?

I wish to use part of the doodle demo code in my project. I then wish to
     

display a number of doodles at roughly 1/64 (1/8H x 1/8W) of the original
size. I think I can achieve this by saving the doodle in a standard format
and just displaying it at its new size.

Q: Where would I start to be able to save a doodle in a standard format,
     

like JPEG or PNG?

Thanks in advance.

Mike

Mike,

PIL, the Python Imaging Library can import and export many file formats.

Barry

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

I'll give it a go over the next couple of days and let you know. Thanks

···

----- Original Message -----
From: "Barry Tolnas" <tolnasb@evergreen.edu>
To: <wxPython-users@lists.wxwindows.org>
Sent: Monday, November 03, 2003 10:09 AM
Subject: Re: [wxPython-users] Doodle to JPEG (or whatever)

Hi Mike,

Now I see you problem. I'm afraid I'm not really familiar with PIL
beyond its basic capabilities. (No experience doing anything but
tutorials with it) However, I have an idea: One approach that might work
is to change doodle so that either it draws into a wxBitmap (see docs on
wxMemoryDC) and then draws the bitmap to the visible window, or draws
into the windowas it does now, but then repeats the same drawing command
to a wxMemoryDC. You can convert a wxBitmap (device specific) to a
wxImage (device independent) which has methods which can write it out to
various standard image file formats.

I've never actually tried this, but the documentation implies it would

work.

Hope that helps,
Barry

Mike Edmonds wrote:

>Barry
>
>Thanks, yes, I have had a look at that. It is the 'importing' that stumps
>me, since the doodle doesn't start out life as a file, but rather a ..

well,

>um... a doodle. The format of a saved file (using superdoodle.py) is that

of

>a doodle (.ddl file) which PIL doesn't appear to support (and why should

it,

>I guess).
>
>What I need to be able to do is use something like PIL to take a portion

of

>the screen and save it.
>
>Can you point me to a PIL routine that might help?
>
>Mike
>----- Original Message -----
>From: "Barry Tolnas" <tolnasb@evergreen.edu>
>To: <wxPython-users@lists.wxwindows.org>
>Sent: Monday, November 03, 2003 8:06 AM
>Subject: Re: [wxPython-users] Doodle to JPEG (or whatever)
>
>
>
>
>>Mike Edmonds wrote:
>>
>>
>>
>>>As a newbie, can someone point me in the right direction?
>>>
>>>I wish to use part of the doodle demo code in my project. I then wish

to

>>>
>>>
>display a number of doodles at roughly 1/64 (1/8H x 1/8W) of the original
>size. I think I can achieve this by saving the doodle in a standard

format

>and just displaying it at its new size.
>
>
>>>Q: Where would I start to be able to save a doodle in a standard

format,

>>>
>>>
>like JPEG or PNG?
>
>
>>>Thanks in advance.
>>>
>>>Mike
>>>
>>>
>>>
>>>
>>Mike,
>>
>>PIL, the Python Imaging Library can import and export many file formats.
>>
>>Barry
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
>>For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
>>
>>
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Barry Tolnas wrote:

Hi Mike,

Now I see you problem. I'm afraid I'm not really familiar with PIL beyond its basic capabilities. (No experience doing anything but tutorials with it) However, I have an idea: One approach that might work is to change doodle so that either it draws into a wxBitmap (see docs on wxMemoryDC) and then draws the bitmap to the visible window, or draws into the windowas it does now, but then repeats the same drawing command to a wxMemoryDC. You can convert a wxBitmap (device specific) to a wxImage (device independent) which has methods which can write it out to various standard image file formats.

The DoodleWIndow class already keeps a wxBitmap buffer of the display, self.buffer. You should be able to convert it to a wxImage with no problems and then have a savable image of the current doodle.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks Robin. Maybe you can clear something up.

self.buffer.ConvertToImage()

gives me an error

AttributeError: wxBitmapPtr instance has no attribute 'ConvertToImage'

I cannot find reference to a wxBitMapPtr in any documents. Can you help?

Mike

···

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxPython-users@lists.wxwindows.org>
Sent: Tuesday, November 04, 2003 1:28 PM
Subject: Re: [wxPython-users] Doodle to JPEG (or whatever)

Barry Tolnas wrote:
> Hi Mike,
>
> Now I see you problem. I'm afraid I'm not really familiar with PIL
> beyond its basic capabilities. (No experience doing anything but
> tutorials with it) However, I have an idea: One approach that might work
> is to change doodle so that either it draws into a wxBitmap (see docs on
> wxMemoryDC) and then draws the bitmap to the visible window, or draws
> into the windowas it does now, but then repeats the same drawing command
> to a wxMemoryDC. You can convert a wxBitmap (device specific) to a
> wxImage (device independent) which has methods which can write it out to
> various standard image file formats.

The DoodleWIndow class already keeps a wxBitmap buffer of the display,
self.buffer. You should be able to convert it to a wxImage with no
problems and then have a savable image of the current doodle.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Mike Edmonds wrote:

Thanks Robin. Maybe you can clear something up.

self.buffer.ConvertToImage()

gives me an error

AttributeError: wxBitmapPtr instance has no attribute 'ConvertToImage'

Try wxImageFromBitmap(self.buffer)

I cannot find reference to a wxBitMapPtr in any documents. Can you help?

The *Ptr classes are an implementation detail. Every wxPython class wrapped with SWIG has one. (But they are going to be much less visible in 2.5 because of the new SWIG.)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

That works like a treat. Thanks Robin.

Mike

···

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxPython-users@lists.wxwindows.org>
Sent: Saturday, November 08, 2003 4:54 PM
Subject: Re: [wxPython-users] Doodle to JPEG (or whatever)

Mike Edmonds wrote:
> Thanks Robin. Maybe you can clear something up.
>
> self.buffer.ConvertToImage()
>
> gives me an error
>
> AttributeError: wxBitmapPtr instance has no attribute 'ConvertToImage'

Try wxImageFromBitmap(self.buffer)

>
> I cannot find reference to a wxBitMapPtr in any documents. Can you help?
>

The *Ptr classes are an implementation detail. Every wxPython class
wrapped with SWIG has one. (But they are going to be much less visible
in 2.5 because of the new SWIG.)

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org