c#处理图片格式的转换

时间:2024-03-02 08:52:30

1.png->jpg  备注:该种方式转换可以避免图片黑底问题

                     Image img = Image.FromFile(Application.StartupPath + "\\Sig.png");
                        using (var bmp = new Bitmap(img.Width, img.Height))
                        {
                            bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution);

                            using (var g = Graphics.FromImage(bmp))
                            {
                                g.Clear(Color.White);
                                g.DrawImageUnscaled(img, 0, 0);
                            }
                            bmp.Save(Application.StartupPath + "\\Temp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                          
                          //  if (File.Exists(Application.StartupPath + "\\Temp.jpg"))
                          //  {
                          //      byte[] bTemp = File.ReadAllBytes(Application.StartupPath + "\\Temp.jpg");
                          //      bResult = bTemp;
                          //  }

                        }