473,494 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Resize image from SQL server and display in asp:image

I am storing an image in an SQL database and have one field as an image
datatype. I am also using a webservice to transport data.

I want to be able to resize the image and pass back a thumbnail image in a
byte[] of what is in the database.

I also want to be able to display this image in an <asp:image></asp:image>
control.

Is there any way to do this? Most of the examples that I've seen have used
the technique of having the src of the image set to a separate page with a
querystring value, and have the page do a Response.BinaryWrite(). I don't
want to do it that way becuase that would mean I would have to call the
webservice again, and I only want to call the webservice once.
Thanks in advance,
John Scott.
Jul 21 '05 #1
1 4333
Well,

I sort of solved this one myself....here is what I did [C#]:

first of all I did a query to the database and put the record into an
object. One field in the database is an image data type field and one field
in the object is a byte []. When I pull the record from sql server I store
the image in the object's ImageFile attribute.

I write the object's byte[] into a memory stream.
I use the memory stream to initialze a Bitmap object
I use the GetThumbnailImage method from the Bitmap object to resize the image
Once I have a resized image, I save the image to a new memory stream and
assign the memory stream .ToArray() to the obj.ImageFile attribue and the
byte array gets returned with the new size.

Here's some code:
obj.ImageFile = rs["IMGFILE"];
Byte[] img = obj.ImageFile;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ms.Write(img, 0, img.Length);//write the image to a memory stream

//call a bitmap constructor using the memory stream
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);

//get a thumbnail of the image from the database.
System.Drawing.Image thumb = bmp.GetThumbnailImage(
95,
95,
new System.Drawing.Bitmap.GetThumbnailImageAbort(Thumb nailCallback),
IntPtr.Zero);

bmp.Dispose();//dispose of the original bitmap
System.IO.MemoryStream thumbStream = new System.IO.MemoryStream();
//save the image back to the memory stream
thumb.Save(thumbStream,System.Drawing.Imaging.Imag eFormat.Gif);

//assign the newly sized image back to the object's byte [] attribute
obj.ImageFile = thumbStream.ToArray();

ms.Close(); //close the memory stream
thumbStream.Close();


"John Scott" wrote:
I am storing an image in an SQL database and have one field as an image
datatype. I am also using a webservice to transport data.

I want to be able to resize the image and pass back a thumbnail image in a
byte[] of what is in the database.

I also want to be able to display this image in an <asp:image></asp:image>
control.

Is there any way to do this? Most of the examples that I've seen have used
the technique of having the src of the image set to a separate page with a
querystring value, and have the page do a Response.BinaryWrite(). I don't
want to do it that way becuase that would mean I would have to call the
webservice again, and I only want to call the webservice once.
Thanks in advance,
John Scott.

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
14457
by: Julia Briggs | last post by:
I am struggling to create a PHP function that would take a specified image (JPG, GIF or PNG) from a link, and resize it down to a thumbnail so it will always fit in a 200x250 space. I am hoping...
1
1885
by: David | last post by:
Hello. How can I resize image in Bitmap object?
4
1643
by: Steph | last post by:
Hi, With a database that stores the path of several images, i have: <ASP:TemplateColumn ...> <ItemTemplate> <ASP:Image id="thePicture" ImageUrl=' <% # DataBinder.Eval(Container.DataItem,...
1
776
by: John Scott | last post by:
I am storing an image in an SQL database and have one field as an image datatype. I am also using a webservice to transport data. I want to be able to resize the image and pass back a thumbnail...
2
1634
by: Adam J Knight | last post by:
Hi all, I am trying resize an image using the following code. //resize image System.Drawing.Image ImageUpload =...
1
3739
by: Arjen | last post by:
Hi, I want to resize an image on my server. I tried a lot of samples... but all the time it does resize and saves the images but I can not view the image insize a webbrowser. With an...
3
7900
by: Paul Cheetham | last post by:
Hi, I have an application that will display user-defined images in some asp:image controls. (sets the ImageURL, and is always built from the site root) The problem comes when the images...
3
2546
by: =?Utf-8?B?cGVsZWdrMQ==?= | last post by:
how can i reesize an image so its quallity will stay the same as the original 1? thnaks in advance peleg
3
2433
by: pozze | last post by:
Hi, I've just made the change from ASP to .net. I have a file (code below) that saves a user submitted file to a MS SQL 2005 database. It collects the file name, file size, file type, and lastly...
0
7119
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
7157
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,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7367
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
5453
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
4579
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...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1400
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 ...
0
285
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...

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.