When you upload image at this time if you want to make image to be small the bellow code is use full ,here code it make image size to be 200*200 and save it to website.
///////////////////// CODE //////////////////////////
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string path = Server.MapPath("Photo/") + FileUpload1.PostedFile.FileName;
// Create a bitmap of the content of the fileUpload control in memory
Bitmap originalBMP = new Bitmap(FileUpload1.FileContent);
// Calculate the new image dimensions
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
int newWidth, newHeight;
newWidth = 200;
newHeight = 200;
// Create a new bitmap which will hold the previous resized bitmap
Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
// Create a graphic based on the new bitmap
Graphics oGraphics = Graphics.FromImage(newBMP);
// Set the properties for the new graphic file
oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
// Draw the new graphic based on the resized bitmap
oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);
// Save the new graphic file to the server
newBMP.Save(path);
//newBMP.Save(directory + "tn_" + filename);
// FileUpload1.SaveAs(path);
Image1.ImageUrl = "~/Photo/" + FileUpload1.PostedFile.FileName;
}
}
///////////////////////////////////////////////////////////////////////////
Download Code : UpaloadImageResize.rar
***********************************************************
See Also :
--
/\/ir@\/ <(.'.)>
///////////////////// CODE //////////////////////////
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string path = Server.MapPath("Photo/") + FileUpload1.PostedFile.FileName;
// Create a bitmap of the content of the fileUpload control in memory
Bitmap originalBMP = new Bitmap(FileUpload1.FileContent);
// Calculate the new image dimensions
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
int newWidth, newHeight;
newWidth = 200;
newHeight = 200;
// Create a new bitmap which will hold the previous resized bitmap
Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
// Create a graphic based on the new bitmap
Graphics oGraphics = Graphics.FromImage(newBMP);
// Set the properties for the new graphic file
oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
// Draw the new graphic based on the resized bitmap
oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);
// Save the new graphic file to the server
newBMP.Save(path);
//newBMP.Save(directory + "tn_" + filename);
// FileUpload1.SaveAs(path);
Image1.ImageUrl = "~/Photo/" + FileUpload1.PostedFile.FileName;
}
}
///////////////////////////////////////////////////////////////////////////
Download Code : UpaloadImageResize.rar
***********************************************************
See Also :
- how to crack IDM
- How to change name of start button in xp
- how to connect to facebook without Internet connec...
- How to customize send to menu.
- How to hide folder without any software.
--
/\/ir@\/ <(.'.)>
0 comments:
Post a Comment
Thanks for comment