473,383 Members | 1,864 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,383 software developers and data experts.

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 4319
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
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
by: David | last post by:
Hello. How can I resize image in Bitmap object?
4
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
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
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
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
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
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.