Library code snippets
Resizing images retrieved from SQL server
This is a nice neat way of resizing an image, I've simplified it and de-refactored (?) it for simplicity. Firstly, you ask for your image from the database:
SqlCommand cmd = new SqlCommand( "SELECT image FROM images WHERE id=@id" , connection);
cmd.Parameters.Add( "@id" , Request.QueryString[ "id" ]);
SqlDataReader dr = cmd.ExecuteReader();
Allocate an array of bytes to store it in temporarily:
byte[] image = null;
while (dr.Read())
{
image = (byte[])dr.GetValue(0);
}
dr.Close()
Now you have an array of bytes that contains your image, you can freely load it into a bitmap from the array:
Bitmap b = (Bitmap)Bitmap.FromStream( new MemoryStream(image));
And you can resize that bitmap easily using the overloaded bitmap constructor:
Bitmap output = new Bitmap(b, new Size(320, 240);
One resized bitmap that you can now save or send anywhere - including Response.OutputStream!
Related articles
Related discussion
-
High-Performance .NET Application Development & Architecture
by Manjot Bawa (0 replies)
-
How to Change Default exe Icon in C#.net Windows Application
by sonali.terse (2 replies)
-
update database when the website is nor running on the browser
by hepsy.i (1 replies)
-
how to send javascript enable html page to email using asp.net
by shahid123 (0 replies)
-
how to save email into database in xml format to sql format and how to trigger back in html
by shahid123 (0 replies)
Related podcasts
-
ADO.NET "Astoria" Data Services with Shawn Wildermuth
Scott chats with Shawn Wildermuth, "the ADO Guy," about ADO.NET Data Services, aka "Project Astoria." It's REST for SQL Server. Should you care? What's REST? How does this relate to WCF or ASP.NET?
Events coming up
-
Mar
15
DevWeek 2010
London, United Kingdom
DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET 4.0, Silverlight 3, WCF 4, Visual Studio 2010, REST, Windows Workflow 4, Thread Synchronization, ASP.NET 4.0, SQL Server 2008 R2, LINQ, Unit Testing, CLR & C# 4.0, .NET Patterns, WPF 4, F#, Windows Azure, ADO.NET, Entity Framework, Debugging, T-SQL Tips & Tricks, and more.
I can't stand it when people ONLY thump their products on the forums.
This article is a teaching Article and as such should be left in that realm. Your comments are of ONLY a commercial nature and NO VALUE to any one for learning. Except maybe that you are probably just as guilty of SPAMMING the world....
The easiest way to upload and resize an image to the internet is I-Load.
This component also create an unlimited number of thumbnails from the original image with the required size.
I-Load is a FREE ASP.NET web control with numerous benefits and features.
You can download I-Load (it's FREE!) and view an online demo here:
http://www.radactive.com/en/Products/ILoad/Overview.aspx
Can u explain little more of resizing images when retrived from database with complete sample code /examples
This thread is for discussions of Resizing images retrieved from SQL server.