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

Resizing an image read from SQL database

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
1 2068
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ruby Tuesday | last post by:
I have a section(185pixelsx 185pixels) in my web page to display an image that is stored in a directory. Using php, how do you resize so if: the image dimension is smaller(width and height is...
2
by: Clyde Ellul | last post by:
Hi there. I need to write a simple program that reads a GIF image from an input stream, resizes it, then writes it back to an output stream in the same format (GIF). (JPEG input/output is good...
1
by: Neil Woodvine | last post by:
***Scenario ... I have a DataList with a hyperlink WebControl in the Item Template. I want to display a 64x64 image in the Hyperlink and set the NavigateURL to the full size image. ***Source...
5
by: Jim | last post by:
I've heard that resizing images through PHP (either GD2 or ImageMagick) is a processor intensive exercise. I'm setting up a site where users will be uploading up to 10 images along with the details...
10
by: David W. Simmonds | last post by:
I have a DataList control that has an Image control in the ItemTemplate. I would like to resize the image that goes into that control. I have a series of jpg files that are full size, full...
3
by: Rudy | last post by:
Hello, I'm hoping went through Scott Mitcell's article on true image resizing. Looking through the article, it's not clear where to put the "GetThumbNailImage" method ...
2
by: Brad | last post by:
I have code which takes an image, uploaded from a web page, and saves it to a database. Now I want to always resize an uploaded image before it is saved to the database. My code to resize is...
10
by: mishrarajesh44 | last post by:
hii all, I am facing a problem currently.. i have a script for image uploading and resizing.. the image uploading takes place properly for every size images.. but, the resizing works for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.