473,614 Members | 2,089 Online
Bytes | Software Development & Data Engineering Community
+ 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.Binary Write(). 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 4379
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 GetThumbnailIma ge 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.Memor yStream ms = new System.IO.Memor yStream();
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.GetThumbnai lImage(
95,
95,
new System.Drawing. Bitmap.GetThumb nailImageAbort( ThumbnailCallba ck),
IntPtr.Zero);

bmp.Dispose();//dispose of the original bitmap
System.IO.Memor yStream thumbStream = new System.IO.Memor yStream();
//save the image back to the memory stream
thumb.Save(thum bStream,System. Drawing.Imaging .ImageFormat.Gi f);

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

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


"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.Binary Write(). 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
14465
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 not to have it inserted or read from a database to do this function. Can it be done & someone please help me?
1
1896
by: David | last post by:
Hello. How can I resize image in Bitmap object?
4
1650
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, "PictureRelativePath") %>' /> </ItemTemplate> </ASP:TemplateColumn>
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 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
2
1645
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 = System.Drawing.Image.FromFile(String.Concat(Server.MapPath(FilePath),ImageName)); // create the actual thumbnail image System.Drawing.Image ThumbnailImage =
1
3773
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 imageviewer (desktop application) I can view the image. I believe there is something wrong with the maximum colors... This is what I have now... Image originalBitmap = Image.FromFile("C:\temp\image.jpg", true);
3
7905
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 specified do not exist, as it displays a red cross and the alternate text. What I would like to do is display a default image instead.
3
2555
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
2461
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 the binary data for the file. I can sucessfully take the files out of the databse again and display them in a data grid. I would like to resize the submitted file to a fixed size (say 180 x 120) before I upload it to the database and do this without...
0
8182
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
8627
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
8279
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
6088
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
5540
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
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2568
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
1
1747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1425
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.