473,659 Members | 2,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(d ata.connectionS tring)
'Write your SQL connection here
Dim sqlCom As New SqlCommand("Sel ect Data, Type From
tblTestImageSto rage Where (ID='" & strImageID & "')", sqlConnection)

Dim sqlDataReader As SqlDataReader

sqlConnection.O pen() 'Open Sqlconnection
sqlDataReader = sqlCom.ExecuteR eader 'Execute the SQL command
While sqlDataReader.R ead
Response.Binary Write(sqlDataRe ader.Item("Data ")) 'Writing
the Image retrieved from the database
Response.Conten tType = sqlDataReader.I tem("Type") 'Setting
the type of the retrieved image


End While
sqlConnection.C lose() '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 2082
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****@christi an.netwrote in message
news:%2******** ********@TK2MSF TNGP04.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(d ata.connectionS tring)
'Write your SQL connection here
Dim sqlCom As New SqlCommand("Sel ect Data, Type From
tblTestImageSto rage Where (ID='" & strImageID & "')", sqlConnection)

Dim sqlDataReader As SqlDataReader

sqlConnection.O pen() 'Open Sqlconnection
sqlDataReader = sqlCom.ExecuteR eader 'Execute the SQL command
While sqlDataReader.R ead
Response.Binary Write(sqlDataRe ader.Item("Data ")) 'Writing the
Image retrieved from the database
Response.Conten tType = sqlDataReader.I tem("Type") 'Setting the
type of the retrieved image


End While
sqlConnection.C lose() '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
2856
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 less than 185pixels), display it in the center of the section if the width OR height is larger than 185pixel, resize them with aspect ratio maintained so both width and height is <= 185pixels. Then display it in the center of the section.
2
11256
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 too, but GIF is preferrable). JAI can do this sort of but can't write to GIF format. Also, it looks too complicated for what I need; I'm a bit in a hurry... Is there a simple way of doing what I want? Is there a free,
1
2932
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 Data Item for Databinding is a class with 2 props ... URL Description ***MyMainPage.aspx Page_Load Code ...
5
4725
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 of their product. For each image uploaded (max 500Kb), I'll be resizing it to create a small, medium and large version after which I'll discard the original. My worry is that as the site becomes more popular, the processor time spent resizing...
10
4144
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 resolution (ie. large). I have a database that contains references to the pictures. Currently I have to resize the jpgs manually, and then point the ImageUrl property at that jpg using databinding. This works fine. I would like to avoid the resizing step...
3
1199
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 http://aspnet.4guysfromrolla.com/articles/012203-1.aspx Thanks! Rudy
2
3990
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 below and of course it's not working properly because my web page which displays the resulting image from the database is not showing the image. I **think** the problem is in my converting the bitmap back to a byte array. If I change my code back...
10
7056
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 only small sized iamages.. for eg. resizing takes place for 70 kb sized images but fails for 600kb or more.. my code is below..
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8539
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.