473,378 Members | 1,426 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,378 software developers and data experts.

unsigned char array -> buffer

Hi again,

as I already wrote, I'm trying to get image binary data into a var holding
an unsigned char string and then print it directly to the browser.
I now already did some tries with an array and now found the buffer()
function. - I thought I would have the solution now and also changed stdout
to O_BINARY, but still I don't get the data right:

8<--------8<--------8<--------8<--------8<--------

imgObj = win32com.client.Dispatch("mine.imgsender")
myImgData = buffer(imgObj.getImgData())

msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
sys.stdout.write(myImgData)

8<--------8<--------8<--------8<--------8<--------

I'm really lost and would be very thankful if someone could help me with
that.

Many thanks in advance,
yours Henri

--
| Henri Schomäcker - BYTECONCEPTS, VIRTUAL HOMES
| * * Datendesign für Internet und Intranet
| * * * * http://www.byteconcepts.de
| * * * * http://www.virtual-homes.de
Jul 18 '05 #1
5 2998
Henri Schomaecker wrote:
as I already wrote, I'm trying to get image binary data into a var holding
an unsigned char string and then print it directly to the browser.
I now already did some tries with an array and now found the buffer()
function. - I thought I would have the solution now and also changed
stdout to O_BINARY, but still I don't get the data right:

8<--------8<--------8<--------8<--------8<--------

imgObj = win32com.client.Dispatch("mine.imgsender")
myImgData = buffer(imgObj.getImgData())

msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
sys.stdout.write(myImgData)

8<--------8<--------8<--------8<--------8<--------

I'm really lost and would be very thankful if someone could help me with
that.


That snipplet of code is totally useless, as none of us has your custom
mine.imgsender lying around his harddisk, so we can't possibly know what
data you get, let alone what data you want.

So if you provided us with the actual data that is returned by getImgData we
might be able to help.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
Hi Diez,

oh, I thought I made it clear: The data is a jpg image.
Let me try to explain it like that:

I create a com object, which loads a jpg image and then I request that image
from the com object with the method getImgData().
As answer to getImageData(), the com object returns a SafeArray of unsigned
char (Bytes).

My problem (no problem with asp and perl, same with php) is, that I would
like to read the imagedata directly into a string of unsigned chars and
then print it to the user agent (webbrowser) in binary mode.

So, it would not really make sense to print the imagedata here ;-) - Sorry
for that confusion.

I hope it's clear now and would be very glad, If maybe you could help me.
Again, many thanks in advance,
yours Henri
Diez B. Roggisch wrote:
Henri Schomaecker wrote:
as I already wrote, I'm trying to get image binary data into a var
holding an unsigned char string and then print it directly to the
browser. I now already did some tries with an array and now found the
buffer() function. - I thought I would have the solution now and also
changed stdout to O_BINARY, but still I don't get the data right:

8<--------8<--------8<--------8<--------8<--------

imgObj = win32com.client.Dispatch("mine.imgsender")
myImgData = buffer(imgObj.getImgData())

msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
sys.stdout.write(myImgData)

8<--------8<--------8<--------8<--------8<--------

I'm really lost and would be very thankful if someone could help me with
that.


That snipplet of code is totally useless, as none of us has your custom
mine.imgsender lying around his harddisk, so we can't possibly know what
data you get, let alone what data you want.

So if you provided us with the actual data that is returned by getImgData
we might be able to help.


--
| Henri Schomäcker - BYTECONCEPTS, VIRTUAL HOMES
| * * Datendesign für Internet und Intranet
| * * * * http://www.byteconcepts.de
| * * * * http://www.virtual-homes.de
Jul 18 '05 #3
Hi,
I create a com object, which loads a jpg image and then I request that
image from the com object with the method getImgData().
As answer to getImageData(), the com object returns a SafeArray of
unsigned char (Bytes).

My problem (no problem with asp and perl, same with php) is, that I would
like to read the imagedata directly into a string of unsigned chars and
then print it to the user agent (webbrowser) in binary mode.

So, it would not really make sense to print the imagedata here ;-) - Sorry
for that confusion.


It will - as one can see what you actually get, instead of what you _want_
to get. AFAIK win32 converts variants to appropriate python types, with
arrays returned as lists - so if things work as documented, you shold get
something like this:

l = ["a", "$", ...]

Making that a (binary) string should be a simple matter of

l.join("")

So I'd like to know what you really get- of cours the first few lines are
sufficient, no need to post a 100kb jpeg binary image.
--
Regards,

Diez B. Roggisch
Jul 18 '05 #4
Bonsoir !

Hi !


Attention, risque de problème (confusion) avec les chaînes à zéro terminal.

Attention, risk of problem (confusion) with the string with zero terminal.


*sorry for my bad english*


@-salutations
--
Michel Claveau

Jul 18 '05 #5
> My problem (no problem with asp and perl, same with php) is, that I would
like to read the imagedata directly into a string of unsigned chars and
then print it to the user agent (webbrowser) in binary mode.

# this example assumes you are using PIL
# this example assume mod_python, but can be easily modified.
def displayJpeg():
im = Image.Open(file)
imdata = StringIO()
im.save(imdata, "JPEG")
del im

req.content_type = "Content-type: image/jpeg"
return imdata.getValue()

Hope this helps in some way? I think I might have misunderstood the
question though.
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: wallacej | last post by:
Does anybody know why unsigned char myImage; works but unsigned char myImage; does not? I think its because the second line is a value too big for unsigned char, is this ...
43
by: M-One | last post by:
See subject: how do I calloc (and free the memory, if that's not free(my_bytes);) this? TIA!
2
by: Goran | last post by:
Hi! I need to convert from a unsigned char array to a float. I don't think i get the right results in the program below. unsigned char array1 = { 0xde, 0xc2, 0x44, 0x23}; //I'm not sure in...
18
by: No Such Luck | last post by:
Hi all: I have an unsigned char array (size 4): unsigned char array; array = 0x00; array = 0x00; array = 0x02; array = 0xe7;
4
by: cdrom205 | last post by:
static void MDString ( unsigned char *input) { MD5_CTX context; unsigned char digest; unsigned int len = sizeof(input);//strlen (const char*) md5.MD5Init (&context); md5.MD5Update...
5
by: Stephen Cawood | last post by:
I'm trying to use a C++ .lib from C# (I tried the Interop group will no results). I have a working wrapper DLL (I can get back simple things like int), but I'm having issues dealing with an array...
10
by: sposes | last post by:
Im very much a newbie but perhaps somehone can help me. Ive been searching for a way to convert a std::string to a unsigned char* The situation is I have a function that wants a unsigned char*...
4
by: Cactus | last post by:
How to convert unsigned char* to CString: I wrote some function: u_char_ =55; u_char_ =66; u_char_ =77; .........=ii...... Convert_to_CS(u_char_);
3
by: uche | last post by:
Please give me some feed back on this issue: Here is the complier error: hexdmp.cpp: In function `void output(unsigned char, int, bool&)': hexdmp.cpp:133: error: invalid types `unsigned char'...
30
by: Yevgen Muntyan | last post by:
Hey, Why is it legal to do union U {unsigned char u; int a;}; union U u; u.a = 1; u.u; I tried to find it in the standard, but I only found that
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.