how to Byte[] ->image?

B

Bimawen

Hi,

I tried to grab an image from the internet, forexample from
www.microsoft.com/image1.jpg, by using WinHttp. but WinHttp.ResponseBody is
a byte[], so when I tried to show them back to my browser by using:

Response.BinaryWrite(objWinHttp.ResponseBody)

it shows like a mess of letters. So my question is how can I show it up
correctly? A further question is

can I save it as an image file?

Thanks!

Bimawen
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Bimawen said:
Hi,

I tried to grab an image from the internet, forexample from
www.microsoft.com/image1.jpg, by using WinHttp. but WinHttp.ResponseBody is
a byte[], so when I tried to show them back to my browser by using:

Response.BinaryWrite(objWinHttp.ResponseBody)

it shows like a mess of letters. So my question is how can I show it up
correctly?

Set the content-type of the response to the mime type for the image.

Example:

Response.ContentType = "image/jpeg";
A further question is

can I save it as an image file?

Yes. Just write the bytes to a file.

Example:

File.WriteAllBytes("c:\test.jpg", objWinHttp.ResponseBody);
 
B

Bimawen

Thank you for your instruction. I tried your sample code, but I still cannot
see the image. This time, the page did not show up the mess of codes(or
letter), instead of a broken image icon with image size 0x0.

And it could be saved into a jpg file, but no program can open it.

Any idea?

Thank you very much!

Bimawen

Göran Andersson said:
Bimawen said:
Hi,

I tried to grab an image from the internet, forexample from
www.microsoft.com/image1.jpg, by using WinHttp. but WinHttp.ResponseBody
is a byte[], so when I tried to show them back to my browser by using:

Response.BinaryWrite(objWinHttp.ResponseBody)

it shows like a mess of letters. So my question is how can I show it up
correctly?

Set the content-type of the response to the mime type for the image.

Example:

Response.ContentType = "image/jpeg";
A further question is

can I save it as an image file?

Yes. Just write the bytes to a file.

Example:

File.WriteAllBytes("c:\test.jpg", objWinHttp.ResponseBody);
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Make sure that there is nothing more sent to the browser than the image
data, for example markup code that is rendered to the browser.

Thank you for your instruction. I tried your sample code, but I still cannot
see the image. This time, the page did not show up the mess of codes(or
letter), instead of a broken image icon with image size 0x0.

And it could be saved into a jpg file, but no program can open it.

Any idea?

Thank you very much!

Bimawen

Göran Andersson said:
Bimawen said:
Hi,

I tried to grab an image from the internet, forexample from
www.microsoft.com/image1.jpg, by using WinHttp. but WinHttp.ResponseBody
is a byte[], so when I tried to show them back to my browser by using:

Response.BinaryWrite(objWinHttp.ResponseBody)

it shows like a mess of letters. So my question is how can I show it up
correctly?
Set the content-type of the response to the mime type for the image.

Example:

Response.ContentType = "image/jpeg";
A further question is

can I save it as an image file?
Yes. Just write the bytes to a file.

Example:

File.WriteAllBytes("c:\test.jpg", objWinHttp.ResponseBody);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top