This is a discussion on How to create a Thumbnail Images even the users give in different ration in c#. within the C# Programming forums, part of the Software Development category; How to create a Thumbnail Images even the users give in different ration in c#....
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| How to create a Thumbnail Images even the users give in different ration in c#.
__________________ H2O Without us, no one can survive.. |
| Sponsored Links |
| |||
| float ratio; float imgHeight = 0; float imgWidth = 0; float boxWidth = 70; float boxHeight = 50; string file = Request.QueryString["file"]; string bwidth = Request.QueryString["Width"]; string bheight = Request.QueryString["height"]; if (!String.IsNullOrEmpty(bwidth)) boxWidth = float.Parse(bwidth); if (!String.IsNullOrEmpty(bheight)) boxHeight = float.Parse(bheight); if (!File.Exists(file)) { file = Server.MapPath("Images/img_empty_user.gif"); } System.Drawing.Image image = System.Drawing.Image.FromFile(file); imgHeight = image.Height; imgWidth = image.Width; ratio = (float)imgHeight / imgWidth; imgWidth = boxWidth; imgHeight = ratio * boxWidth; imgHeight = boxHeight; System.Drawing.Image thumbnailImage = image.GetThumbnailImage((int)imgWidth, (int)imgHeight, new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback), IntPtr.Zero); // make a memory stream to work with the image bytes MemoryStream imageStream = new MemoryStream(); // put the image into the memory stream thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); // make byte array the same size as the image byte[] imageContent = new Byte[imageStream.Length]; // rewind the memory stream imageStream.Position = 0; // load the byte array with the image imageStream.Read(imageContent, 0, (int)imageStream.Length); // return byte array to caller with image type Response.ContentType = "image/jpeg"; Response.BinaryWrite(imageContent); |
| |||
| Hey Venkat, This is the method with which we can do Image Cropping in c#.Net in a more easier way. public static Image Crop(Image image, int cropLeft, int cropTop, int cropWidth, int cropHeight) { Bitmap newImage = new Bitmap(cropWidth, cropHeight); Graphics g = Graphics.FromImage(newImage); newImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); g.DrawImage(image, new Rectangle(0, 0, cropWidth, cropHeight), new Rectangle(cropLeft, cropTop, cropWidth, cropHeight), GraphicsUnit.Pixel); return (Image)newImage; }
__________________ Sathish Kumar.R ![]() Knowledge is meant to SHARE |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to create BMP thumbnail image in PHP? | Jeyaseelansarc | PHP Programming | 2 | 10-13-2007 01:05 AM |
| Create thumbnail for Video in PHP | Jeyaseelansarc | PHP Programming | 1 | 09-10-2007 07:51 AM |
| Select Thumbnail images and view the larger image | H2o | HTML, CSS and Javascript Coding Techniques | 1 | 08-07-2007 08:58 AM |
| who is the normal user in TFS website ? How can I give the permission for users to ac | kingmaker | ASP and ASP.NET Programming | 0 | 07-24-2007 05:14 AM |
| Create thumbnail for Video in PHP | Jeyaseelansarc | PHP Programming | 0 | 03-12-2007 07:06 AM |