Fellow wxPythoneers,
I was thinking that pickling image data (as returned by wxImage::GetData())
would be silly if I can just pickle the original image file (which is a PNG)
and reload it by unpickling the "file" and then loading the image from that.
The space savings would be enourmous, since the image is 400x350 pixels
(times three, for R, G and B, so 420000 bytes) and the associated PNG file
is a mere 7 KB.
[I want to store my splash screen logo as a pickled string in my code, so
that I don't have an external dependancy to ship and to protect against
tampering, if you're wondering why I don't just load directly from a
file...]
I noticed that wxImage::LoadFile can take a wxInputStream as a parameter,
but the documentation says "wxInputStream is an abstract base class which
may not be used directly". Doh.
Before I start implementing a StringInputStream (and StringOutputStream) of
some sort that subclasses wxInputStream (and wxOuputStream), I'd like to ask
if anybody has done this before (and if there's code I can use) or if
there's a better way of hiding my logo in my code, short of using a
database.
Thanks for your help!
···
----------------------------------------------------------------------
Olivier A. Dagenais - Carleton University - Computer Science III
Olivier Dagenais wrote:
I was thinking that pickling image data (as returned by wxImage::GetData())
would be silly if I can just pickle the original image file (which is a PNG)
and reload it by unpickling the "file" and then loading the image from that.
The space savings would be enourmous, since the image is 400x350 pixels
(times three, for R, G and B, so 420000 bytes) and the associated PNG file
is a mere 7 KB.
[I want to store my splash screen logo as a pickled string in my code, so
that I don't have an external dependancy to ship and to protect against
tampering, if you're wondering why I don't just load directly from a
file...]
This sounds to me like a job for a pure Python solution, rather that
looking for wx to help. The PNG file can be read into a python string
(which I don't believe has any problems with non-printable characters,
if so, you could use a Python array, from the array module). Then use
Pickle to convert this stirng or array into printable ascii, which you
could imbed in your source. Reverse it to get it back.
NOTE: I havn't ever tried to do anything like this, but it usually seems
to be easier to use Python for anything other than the GUI stuff. You
might also want to take a look at PIL, and see if it has anything that
could help.
-Chris
···
--
Christopher Barker,
Ph.D.
cbarker@jps.net --- --- ---
http://www.jps.net/cbarker -----@@ -----@@ -----@@
------@@@ ------@@@ ------@@@
Water Resources Engineering ------ @ ------ @ ------ @
Coastal and Fluvial Hydrodynamics ------- --------- --------
------------------------------------------------------------------------
------------------------------------------------------------------------
Just use a Python string to hold the file data -- use CStringIO if
necessary -- it acts like a file, and is easily pickled.
Charles
···
Olivier Dagenais <olidag42@hotmail.com> wrote:
I was thinking that pickling image data (as returned by wxImage::GetData())
would be silly if I can just pickle the original image file (which is a PNG)
and reload it by unpickling the "file" and then loading the image from that.
The space savings would be enourmous, since the image is 400x350 pixels
(times three, for R, G and B, so 420000 bytes) and the associated PNG file
is a mere 7 KB.
--
-----------------------------------------------------------------------
Charles Cazabon <wxpython@discworld.dyndns.org>
GPL'ed software available at: http://www.qcc.sk.ca/~charlesc/software/
My opinions are just that -- my opinions.
-----------------------------------------------------------------------