Resizing an image read from SQL database

B

Blasting Cap

I would like to try to see if an image uploaded to a SQL database is
over a specific size, and if so, to resize it when it is displayed. The
following is in the Page_load event.

Dim strImageID As String = "10" 'Request the value of ImageID

Dim data As New data
Dim sqlConnection As New SqlConnection(data.connectionString)
'Write your SQL connection here
Dim sqlCom As New SqlCommand("Select Data, Type From
tblTestImageStorage Where (ID='" & strImageID & "')", sqlConnection)

Dim sqlDataReader As SqlDataReader

sqlConnection.Open() 'Open Sqlconnection
sqlDataReader = sqlCom.ExecuteReader 'Execute the SQL command
While sqlDataReader.Read
Response.BinaryWrite(sqlDataReader.Item("Data")) 'Writing
the Image retrieved from the database
Response.ContentType = sqlDataReader.Item("Type") 'Setting
the type of the retrieved image




End While
sqlConnection.Close() 'Close Sqlconnection



How can I resize it, checking to make sure that if it's 3000x2000 I want
to resize to 800x600?

Nothing I've tried has worked. Trying to use the system.drawing.image
(an article from Rolla) gives me an invalid cast.

Any help appreciated.

BC
 
M

Mark Fitzpatrick

You'll have to use the System.Drawing classes to do it. You may have to get
the data read into a memory stream first, then create an image from it.
There's an article at http://www.odetocode.com/Articles/172.aspx that may
help give some general ideas. Basically though, there's no other way to
manipulate the image until you load it into the approprate image class.
 

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,586
Members
45,090
Latest member
ActivlifeKetoDiet

Latest Threads

Top