IT Community - Software Programming, Web Development and Technical Support

How to create a Thumbnail Images even the users give in different ration in c#.

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#....


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-08-2007, 06:13 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Question How to create a Thumbnail Images even the users give in different ration in c#.

How to create a Thumbnail Images even the users give in different ration in c#.
__________________
H2O

Without us, no one can survive..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-08-2007, 06:35 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: How to create a Thumbnail Images even the users give in different ration in c#.

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);
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-10-2007, 12:07 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Exclamation Re: How to create a Thumbnail Images even the users give in different ration in c#.

So,you are explaining how image cropping can be done?Am i right?

Regards,
Sathish kumar.R
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-10-2007, 12:20 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: How to create a Thumbnail Images even the users give in different ration in c#.

hey,


Yeah, please give me example for Image Cropping to implement in project.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-10-2007, 01:00 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Re: How to create a Thumbnail Images even the users give in different ration in c#.

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 04:58 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0