Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how we can resize the size of given image using two text box in window application c# please sent me code for my project becouse i sent it through mail.....
Posted
Comments
BillWoodruff 4-Feb-14 6:32am    
Please provide more information on what the two TextBoxes do, and tell us what you have tried so far, and show some code.

1 solution

I guess that the mentioned textboxes determine the desired width and height of the resulting image. If that's the case, you can replace them with NumericUpDowns. Their benefit is that you are guaranteed to get a Value of Decimal type without needing to parse input. A simple boundary check suffices.

Create a new image object using the dimensions you got, get a Graphics object from it and use that to draw the original image. It will result in being drawn onto the new image with new size:
System.Drawing.Image Resize(System.Drawing.Image sourceImage, int targetWidt, int targetHeight)
{
    System.Drawing.Image targetImage = new System.Drawing.Bitmap(targetWidt, targetHeight);
    System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(targetImage);

    graphics.DrawImage(sourceImage, 0, 0, targetWidt, targetHeight);

    return (targetImage);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900