我正在努力将所有图片格式更改为.gif格式,但在更改为新格式后,它的质量会下降。我使用以下代码更改格式。
String paths = HttpContext.Current.Request.PhysicalApplicationPath + "DesktopModules\\DNAiusParallelSlider\\Images\\"+ModuleId.ToString()+"\\";
if (FileUpload2.HasFile)
{
string extension = Path.GetExtension(FileUpload2.PostedFile.FileName);
FileUpload2.SaveAs(paths + "waves" + extension);
System.Drawing.Image image1 = System.Drawing.Image.FromFile(@paths + "\\waves" + extension);
System.Drawing.Image img = System.Drawing.Image.FromFile(@paths + "\\waves" + extension);
if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
{
image1.Save(@paths + "\\waves.gif", System.Drawing.Imaging.ImageFormat.Gif);
}
if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Bmp))
{
image1.Save(@paths + "\\waves.gif", System.Drawing.Imaging.ImageFormat.Gif);
}
if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png))
{
image1.Save(@paths + "\\waves.gif", System.Drawing.Imaging.ImageFormat.Gif);
}
if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Tiff))
{
image1.Save(@paths + "\\waves.gif", System.Drawing.Imaging.ImageFormat.Gif);
}
if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Emf))
{
image1.Save(@paths + "\\waves.gif", System.Drawing.Imaging.ImageFormat.Gif);
}
if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Wmf))
{
image1.Save(@paths + "\\waves.gif", System.Drawing.Imaging.ImageFormat.Gif);
}
// Save the image in PNG format.
}
答案 0 :(得分:1)
我认为转换为gif时会不可避免地会失去质量,特别是从
转换JPEG和PNG。这是因为Gif是8位格式,这意味着格式支持的最大颜色数为256。
因为近似,你可能会因颜色的不同而失去细微的色调。
GIF适用于只有少量不同颜色的图像,例如线条图和简单卡通。
如果您仍然怀疑自己的c#代码,可以转到this online image converter查看质量。