我正在努力将所有图像格式更改为 .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.
}