By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,352 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,352 IT Pros & Developers. It's quick & easy.

Resizing an image read from SQL database

P: n/a
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
Oct 17 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Blasting Cap" <go****@christian.netwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>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

Oct 17 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.