C#斷定一個圖象能否是通明的GIF圖的辦法。本站提示廣大學習愛好者:(C#斷定一個圖象能否是通明的GIF圖的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#斷定一個圖象能否是通明的GIF圖的辦法正文
本文實例講述了C#斷定一個圖象能否是通明的GIF圖的辦法。分享給年夜家供年夜家參考。詳細以下:
1. 應用辦法以下:
System.Drawing.Image objImage = DownloadImage("https://www.谷歌.com/images/srpr/logo3w.png"); if (IsTransparentPalette(objImage.Palette)) {//your code....}
2. C#代碼以下:
public bool IsTransparentPalette(System.Drawing.Imaging.ColorPalette palette) { if (palette.Flags!= 1 ) return false; int total_colors = palette.Entries.GetLength(0); for (int i = 0; i < total_colors - 1; i++) { if (palette.Entries[i].A != 0) { return false; } } return true; } public System.Drawing.Image DownloadImage(string url) { System.Drawing.Image tmpImage = null; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AllowWriteStreamBuffering = true; request.UserAgent = UserAgent; request.Accept = "GET HTTP/1.1"; request.Timeout = 2000; System.Net.WebResponse webResponse = request.GetResponse(); System.IO.Stream webStream = webResponse.GetResponseStream(); if (webStream != null) tmpImage = System.Drawing.Image.FromStream(webStream); webResponse.Close(); webResponse.Close(); } catch (Exception exception) { return null; } return tmpImage; }
願望本文所述對年夜家的C#法式設計有所贊助。