C#判断一个图像是否是透明的GIF图的方法
程序员文章站
2023-11-27 13:27:40
本文实例讲述了c#判断一个图像是否是透明的gif图的方法。分享给大家供大家参考。具体如下:
1. 使用方法如下:
system.drawing.image ob...
本文实例讲述了c#判断一个图像是否是透明的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; }
希望本文所述对大家的c#程序设计有所帮助。