Using response.write to display system.drawing.image

D

Dave Keen

Hi all.

Hope you can help me. This should be easy but I can't make this work.
In brief I am building a page of thumbnails using images held in a
SQLServer 2000 database. I do this by creating imagebuttons which
point to a dummy page that takes the image and displays it via
response. All works fine if I use explicit paths to a file
(response.writefile(<filename>) or directly pass through the database
image (response.binarywrite(<dbimage>), but I convert the db image to
system.drawing.image so as to resize etc, and once I do that I can't
display it.

I have used the following code to take the database image, convert it
into a system.drawing.image and show the results (this is obviously a
cut down version of the original).

Dim clsTableImage As New TableImage
If clsTableImage.GetRecord(CType(1, Short)) = 0 Then
' Make an image object of the image using a stream
Dim FullSizeImage As System.Drawing.Image
Dim fs As New System.IO.MemoryStream
Dim w As New System.IO.BinaryWriter(fs)
w.Write(clsTableImage.Image)
FullSizeImage = System.Drawing.Image.FromStream(fs)

'Response.ContentType = "image/jpeg"
Response.Write(FullSizeImage)
End If

clsTableImage is a class that returns the image as a byte array. What
I get out of this is the text "system.drawing.bitmap". So, how do I
send a system.drawing.image to the form in ASP 1.1?

Thanks in advance.

Dave
 
R

Robbe Morris [C# MVP]

You would typically Response.Write the byte array itself.
No need to create an image from it.

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp
 
D

Dave Keen

Hi Robbe

Thanks for your thoughts. Unfortunately I have to convert to an image
object as I want to resize and manipulate the image before showing it.
Remember I said the code I gave was a simplified version. After I take
the byte array and convert to an image which I have changed in various
ways I need to pass that image object to the form. How?

Cheers

Dave
 
D

Dave Keen

Hi Robbe

Thanks for your thoughts. Unfortunately I have to convert to an image
object as I want to resize and manipulate the image before showing it.
Remember I said the code I gave was a simplified version. After I take
the byte array and convert to an image which I have changed in various
ways I need to pass that image object to the form. How?

Cheers

Dave
 
Joined
Mar 31, 2009
Messages
2
Reaction score
0
Nishant makvana

Dim FullSizeImage As System.Drawing.Image
Dim fs As New System.IO.MemoryStream
Dim w As New System.IO.BinaryWriter(fs)
w.Write(clsTableImage.Image)
FullSizeImage = System.Drawing.Image.FromStream(fs)
FullSizeImage.Save(Server.MapPath("~/destinationFolder/imagename.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
ASPNETImageControl.ImageUrl = "~/destinationFolder/imagename.jpg";
 
Joined
Mar 31, 2009
Messages
2
Reaction score
0
Display System.Drawing.Image in ASP.NET Image Cotrol

Dim FullSizeImage As System.Drawing.Image
Dim fs As New System.IO.MemoryStream
Dim w As New System.IO.BinaryWriter(fs)
w.Write(clsTableImage.Image)
FullSizeImage = System.Drawing.Image.FromStream(fs)
FullSizeImage.Save(Server.MapPath("~/destinationFolder/imagename.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
ASPNETImageControl.ImageUrl = "~/destinationFolder/imagename.jpg";

Now you can See the image in your own webpage and in image control.

Display
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top