旋转后的图像大小以mb为单位增加



一些图像正在web中旋转。因此,我在RotateFlipType.Rotate90FlipNone的帮助下旋转了后端的图像,并保存了新图像。但是图像大小增加了很多。

像200kb在旋转后变成4MB。

是否有任何方法可以控制旋转图像的大小,但保持与原始图像相同的尺寸。

代码

string filename = imagePath.Substring(imagePath.LastIndexOf("/") + 1);
Image image = Image.FromFile(Server.MapPath("~/files/" + filename));
using (Graphics g = Graphics.FromImage(image))
{
if (image.PropertyItems.Any(p => p.Id == 274))
{
if (image.PropertyItems.Any(p => p.Value[0] == 6))
{
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
string fileNameWithoutExtnsn = Path.GetFileNameWithoutExtension(imagePath);
fileNameWithoutExtnsn = fileNameWithoutExtnsn + '1';
string fileExtnsn = Path.GetExtension(imagePath);
filename = string.Format("{0}{1}", fileNameWithoutExtnsn, fileExtnsn);
filePath = string.Format("{0}/{1}/{2}", urlPath, "files", filename);
try
{
image.Save(Path.Combine(Server.MapPath("~/files/"), filename));
}
catch (Exception ex)
{
throw;
}
}
}                   
}

RotateFlip将格式转换为MemoryBmp。因此,将图像保存为Jpeg

image.Save("filePath", ImageFormat.Jpeg);

最新更新