int newWidthIn = 160;
int newHeightIn = 200;
// Create a bitmap of the content of the fileUpload control in memory
Bitmap originalBMP = new Bitmap(FilePath);
// Calculate the new image dimensions
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
float sngRatio = 1;
int newWidth = 0;
int newHeight = 0;
if (origWidth > newWidthIn || origHeight > newHeightIn)
{
if (origWidth > origHeight)
{
sngRatio = (float)origWidth / (float)origHeight;
newWidth = newWidthIn;
newHeight = Convert.ToInt32(newWidthIn / sngRatio);
}
else if (origWidth < origHeight)
{
sngRatio = (float)origHeight / (float)origWidth;
newHeight = newHeightIn;
newWidth = Convert.ToInt32(newHeightIn / sngRatio);
}
else
{
if (origWidth > newWidthIn)
{
sngRatio = (float)origWidth / (float)newWidthIn;
newWidth = newWidthIn;
newHeight = Convert.ToInt32(origHeight / sngRatio);
}
else if (origHeight > newHeightIn)
{
sngRatio = (float)origHeight / (float)newHeightIn;
newHeight = newHeightIn;
newWidth = Convert.ToInt32(origWidth / sngRatio);
}
}
// 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 resize Image ------------- //
newBMP.Save(FilePath);
// Once finished with the bitmap objects, we deallocate them.
originalBMP.Dispose();
newBMP.Dispose();
oGraphics.Dispose();
}
else
{
fuPicture.SaveAs(Server.MapPath(FilePath));
}
سلام وقت بخیر من می خوام عکس رو resize کنم اما با این خطا مواجه میشم:
این لینک رو ببینید
سلام استاد منم همین مشکل رو دارم کد هایی که نوشتم همون کدی هست که خودتون گفتید اما باز هم خطا میده لطفا ببیشتر توضیح بدین
ممنون
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)