Я хочу сжать фотографии в asp.net, но код я использую те, которые не полностью сжимают файлы, как только они все еще очень огромны. Как я могу уменьшить размер?Сжатие изображений в asp.net
string directory = Server.MapPath("~/listingImages/" + date + filename);
// Create a bitmap of the conten t of the fileUpload control in memory
Bitmap originalBMP = new Bitmap(AsyncFileUpload1.FileContent);
// Calculate the new image dimensions
decimal origWidth = originalBMP.Width;
decimal origHeight = originalBMP.Height;
decimal sngRatio = origHeight/origWidth;
int newHeight = 300; //hight in pixels
decimal newWidth_temp = newHeight/sngRatio;
int newWidth = Convert.ToInt16(newWidth_temp);
// 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.Bicubic;
// 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(Server.MapPath("~/listingImages/" + date + filename));
Прочтите это http://www.c-sharpcorner.com/uploadfile/rahuldebray/compress-image-to-a-given-size/ – Nalaka
Ваш код ничего не сжимает, он сохраняет несжатое растровое изображение. Вы должны установить формат изображения, который хотите использовать при вызове –