欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)文章

最新評(píng)論