473,412 Members | 2,005 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,412 software developers and data experts.

how to Byte[] ->image?

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
Mar 1 '07 #1
3 1554
Bimawen wrote:
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);

--
Göran Andersson
_____
http://www.guffa.com
Mar 1 '07 #2
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" <gu***@guffa.comwrote in message
news:ee**************@TK2MSFTNGP06.phx.gbl...
Bimawen wrote:
>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);

--
Göran Andersson
_____
http://www.guffa.com

Mar 12 '07 #3
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.
Bimawen wrote:
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" <gu***@guffa.comwrote in message
news:ee**************@TK2MSFTNGP06.phx.gbl...
>Bimawen wrote:
>>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);

--
Göran Andersson
_____
http://www.guffa.com

--
Göran Andersson
_____
http://www.guffa.com
Mar 13 '07 #4

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

Similar topics

1
by: Telmo Costa | last post by:
Hi. I'm trying to load an image and copy it to an array of bytes. The image is a png 32bit format. The code I have is: ------------------------------------------------------------- public void...
1
by: Adam | last post by:
I am having difficulty retrieving images from a SQL database. Here is the code I use to UPLOAD the image to the database: <form id="Form1" method="post" enctype="multipart/form-data"...
1
by: Thubaiti | last post by:
Hi, I have an image web control with other web controls.. <asp:Image id="itemImage" runat="server"></asp:Image> <asp:Label id="itemNameLabel" runat="server"></asp:Label> <asp:Label...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
0
by: sebascomeau | last post by:
Hi everyone, Hello my name is Sebastien and I need some help. He have one week past and I search to do one thing but I can't. If someone help me, I'll be so happy :). My problem is I want to...
3
by: Chris | last post by:
I need to load an rtf file to my sql database (into image type column). now I am using external tool textcopy.exe (launched within my application) Is it possible (how to do that) to write my own...
2
by: Roel | last post by:
Hi, I'm using the ASP.NET 2.0 profile system to keep an image of members of my website "MyWebsite". Initially, I've created the property in the web.config like: <add name="Photo"...
4
by: IceDiver | last post by:
I hope someone can help.... I'm looking for ways to parse PBYTE image data created by GDI (via Unidrv) and search for a word. The original data consisted of images and text. Any idea? Thanks...
1
by: sarran rangarajan | last post by:
Hi, i have collection of memorystream. I need to write (generate) an image based on data that is present in all memorystreams. string p = string.Format(@"C:\temp\{0}-Page.gif", messageId);...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...
0
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...

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.