Stream into System.Drawing.Image

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I get from database a field of type binary (its a gif image) into byte[]
until here no problem, cause i veryfied that the binary its stored into the
byte[] variable (called arrayb in my application).

Im trying show into Internet explorer this byte[] (arrayb its the name of
the variable) this way:

1) MemoryStream imgStream=new MemoryStream(arrayb,0,arrayb.Length, false,
true);
2) System.Drawing.Image tmpimg=System.Drawing.Image.FromStream(imgStream);

Question 1) Why im getting an error in the step 2 that says?: Invalid
parameter used.

Question 2) How could i show the image into a HtmlGenericControl?
 
Josema,

If you want to show the image back in internet explorer, you probably
don't want to load the bytes into an Image (Bitmap) object. Rather, you
need to return an IMG tag which points to an ASP.NET page. This tag would
have a SRC attribute that has the url of the page, along with an identifier
of some sort in the query string which you can use to fetch the contents of
the image from the database.

Then, in the other ASP.NET page, change the content type of the response
to "image/jpeg" (or whatever your format is), and then fetch the bytes from
the database based on the identifer in the query string. Once you have the
bytes, clear the response stream (the response needs to be buffered for
this, I believe) and then write the bytes in the response stream.

Hope this helps.
 
Hi Nicholas, first to all agree to you for the fast answer,

My exactly problem its that:

I have in a database models of cars,

CarID int
CarName varchar
CarFeatures varchar
CarImage binary

I have a class Car that have the properties:
ID int
Name string
Features string
Image byte[]

My problem its that i have into a page a

<span id=CarGenericControl runat=server>

and inside the CarGenericControl.InnerHtml

I have to show the Name, Features, and Image foto of the car.

In this moment i show all the information except the foto, that i dont
know how to put it from byte[] into the Generic Control.

Do you have any advice for this specific case?

Thanks.
Kind Regards.
Josema
 
Back
Top