473,799 Members | 2,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1456
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.roge rs.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_ParseTupl e 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_ParseTu ple(args, "s", &string))
return NULL;

you do this:

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

if (!PyArg_ParseTu ple(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.roge rs.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
2039
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
3921
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 then printed and mailed out or faxed. It would be nice to have the doc's electronic signature show up on this report, but we have 4 or 5 docs that order tests. So, I would like to use a combo box on this form to select from a
6
8843
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 clicks a cmd button to open the Windows API Common Dialog and selects a new file (jpeg). Images are initially loaded in the form's oncurrent event. I've tried using me.dirty = false to make the form current. Has anyone experienced this before?
4
13760
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 mostly scanned newspaper atricles which are too big to just display on a form so I need the zoom and scroll features. Im using access 2003
4
7201
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 value of each pixel. But I want to be able to do this with all types of image formats. It was suggested that a function such as 'B = numeric.from_image(A)' was used but I can't find it in any of the libraries. I was hoping you could help me on this....
4
2757
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. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
1
2399
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 i am able to download the image.... But my problem is i want to get that image to be stored in the particular file path,(eg)" /home/image" ..I dont know how to do this...can some one heil me to overcome this problem..
3
4979
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 successive folder in the format Pic#, i,e. Pic1, Pic2 etc. What I want to do is make a slider that is attached to a label which would output the slide number that is being looked at. I would use that number then to return the image of the slide...
1
11095
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 StringIO objects being passed in place of file objects. StringIO objects are binary strings of variable length that are kept in memory so i saved the image in stringio objects the following code does that for gif image ...
0
9540
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10250
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.