473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Image Module Bug

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
3 1439
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nicholas S. Graham | last post by:
I want to convert a field of 4:2:2 digital video data into a viewable format (.jpg or something) using the Image module. Any suggestions?? NG
3
by: Ranman | last post by:
Hi all, I have a simple problem that hopefully has a simple solution, but I have yet to figure it out. In a patient database, I have a physician test order form that populates a report that is...
6
by: Arnold | last post by:
Hey there, I've browsed for some fixes to this but only found a couple of similar posts, which didn't solve my problem. I'm wondering how to refresh an image control in a form after a user...
4
by: Shumit Rehman | last post by:
Hi I have a table which has path names to photos I would like to view. I would like to open some/any kind of image viewer(Paint) to see the picture when I click the pathname. The pictures are...
4
by: Dimitrios Charitatos | last post by:
Hello, I suspect that there is a quite straight forward answer to this, but I can't find it... I want to import an image and extract a matrix (or array) from it with elements showing the RGB...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
1
by: Lastknight | last post by:
Hi all, i am looking for your help regarding this topic... I am trying to download a image from the web through perl program. I have used Image::Grab module for that task,through the module...
3
by: Nebulism | last post by:
Hi everyone, I am working on a module for my GUI that shows one image with an index value below and would use a scrollbar to control which of the images are displayed. The images are stored in a...
1
by: bharathv6 | last post by:
i need to do is modify the image in memory like resizing the image in memory etc ... with out saving it disk as i have to return back the image with out saving it disk PIL supports the use of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.