By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,890 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,890 IT Pros & Developers. It's quick & easy.

Image Module Bug

P: n/a
Hi,

I've got a problem with loading images using the Image Module. When I load
images and then try to pass them to my C++ module using tostring() I get the
following error:

TypeError: argument 1 must be string without null bytes, not str

After tearing my hair out I figured out that it was because there was full
black (0) in my image which was screwing up the NULL string terminator.

Here's my question. How can I get around this? Can I pass the raw image
data in another format? Can I use the encoder options on the tostring()
method? Anyone have any ideas?

This is also a problem when I am trying to do RGBA format because the alpha
channel is 0 in transparent places.

Thanks,
Peter
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You should be able to use the struct module to pack your
data into a binary structure, then pass that to the C++
module. I do this in quite a few programs I have that
need to pass this type of data to C, C++ routines.

HTH,
Larry Bates
Syscon, Inc.

"Jim Bob" <ji*@bob.com> wrote in message
news:gp**********************@news01.bloor.is.net. cable.rogers.com...
Hi,

I've got a problem with loading images using the Image Module. When I load images and then try to pass them to my C++ module using tostring() I get the following error:

TypeError: argument 1 must be string without null bytes, not str

After tearing my hair out I figured out that it was because there was full
black (0) in my image which was screwing up the NULL string terminator.

Here's my question. How can I get around this? Can I pass the raw image
data in another format? Can I use the encoder options on the tostring()
method? Anyone have any ideas?

This is also a problem when I am trying to do RGBA format because the alpha channel is 0 in transparent places.

Thanks,
Peter

Jul 18 '05 #2

P: n/a
I had this problem too a week ago. You should use "s#" with
PyArg_ParseTuple instead of "s". See

http://www.python.org/doc/1.5.2p2/ext/parseTuple.html

So instead of doing something like:

static PyObject *
spam_something(PyObject *self, PyObject *args) {
char *string;

if (!PyArg_ParseTuple(args, "s", &string))
return NULL;

you do this:

static PyObject *
spam_something(PyObject *self, PyObject *args)
char *string;
int length;

if (!PyArg_ParseTuple(args, "s#", &string, &length))
return NULL;

'length' will be length of the string passed from python.

Richard
Jul 18 '05 #3

P: n/a
I found a good way of doing this.

In my interface, I use "s#" instead of "s" to read a string along with its
length. This allows me to pass NULL characters.

"Jim Bob" <ji*@bob.com> wrote in message
news:gp**********************@news01.bloor.is.net. cable.rogers.com...
Hi,

I've got a problem with loading images using the Image Module. When I load images and then try to pass them to my C++ module using tostring() I get the following error:

TypeError: argument 1 must be string without null bytes, not str

After tearing my hair out I figured out that it was because there was full
black (0) in my image which was screwing up the NULL string terminator.

Here's my question. How can I get around this? Can I pass the raw image
data in another format? Can I use the encoder options on the tostring()
method? Anyone have any ideas?

This is also a problem when I am trying to do RGBA format because the alpha channel is 0 in transparent places.

Thanks,
Peter

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.