C#判斷一個(gè)圖像是否是透明的GIF圖的方法
更新時(shí)間:2015年06月16日 14:53:36 作者:紅薯
這篇文章主要介紹了C#判斷一個(gè)圖像是否是透明的GIF圖的方法,涉及C#針對(duì)gif圖片屬性的相關(guān)操作技巧,需要的朋友可以參考下
本文實(shí)例講述了C#判斷一個(gè)圖像是否是透明的GIF圖的方法。分享給大家供大家參考。具體如下:
1. 使用方法如下:
System.Drawing.Image objImage = DownloadImage("https://www.google.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;
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
探討C#中Dispose方法與Close方法的區(qū)別詳解
本篇文章是對(duì)C#中Dispose方法與Close方法的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
C# 無(wú)邊框窗體邊框陰影效果的簡(jiǎn)單實(shí)現(xiàn)
這篇文章介紹了C# 無(wú)邊框窗體邊框陰影效果的簡(jiǎn)單實(shí)現(xiàn),有需要的朋友可以參考一下2013-10-10
C#在winform中實(shí)現(xiàn)數(shù)據(jù)增刪改查等功能
本篇文章主要是介紹了C#在winform中操作數(shù)據(jù)庫(kù),實(shí)現(xiàn)數(shù)據(jù)增刪改查,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-11-11

