WEB开发网
开发学院WEB开发ASP.NET 如何判断一个图像是否是透明的 GIF 阅读

如何判断一个图像是否是透明的 GIF

 2012-07-07 14:20:17 来源:WEB开发网   
核心提示:System.Drawing.Image objImage = DownloadImage("http://www.7wy.net/images/WaterMap1.png");if (IsTransparentPalette(objImage.Palette)) {//your code....}
System.Drawing.Image objImage = DownloadImage("http://www.7wy.net/images/WaterMap1.png");
if (IsTransparentPalette(objImage.Palette)) {//your code....}     

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

Tags:如何 判断 一个

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接