c#處理圖片格式的轉換


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;
                          //  }

                        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM