代碼 復制代碼 代碼如下: //存成gif.ashx <%@ WebHandler Language="C#" Class="Gif" %> using System.IO; using Syste " /> 99热精品一区,秋霞鲁丝片Av无码,a级销魂美女

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

asp.net 動態輸出透明gif圖片

查了國內幾個中文資料都沒解決,最后是在一個英文博客上找到一個可以用的辦法。
他的解決代碼是:

代碼
復制代碼 代碼如下:
//存成gif.ashx
<%@ WebHandler Language="C#" Class="Gif" %>
using System.IO;
using System.Web;
using System.Drawing;
public class Gif : IHttpHandler {
/// <summary>
/// Returns a transparent background GIF image from the specified Bitmap.
/// </summary>
/// <param name="bitmap">The Bitmap to make transparent.</param>
/// <param name="color">The Color to make transparent.</param>
/// <returns>New Bitmap containing a transparent background gif.</returns>
public Bitmap MakeTransparentGif(Bitmap bitmap, Color color) {
byte R = color.R;
byte G = color.G;
byte B = color.B;
MemoryStream fin = new MemoryStream();
bitmap.Save(fin, System.Drawing.Imaging.ImageFormat.Gif);
MemoryStream fout = new MemoryStream((int)fin.Length);
int count = 0;
byte[] buf = new byte[256];
byte transparentIdx = 0;
fin.Seek(0, SeekOrigin.Begin);
//header
count = fin.Read(buf, 0, 13);
if ((buf[0] != 71) || (buf[1] != 73) || (buf[2] != 70)) return null; //GIF
fout.Write(buf, 0, 13);
int i = 0;
if ((buf[10] & 0x80) > 0) {
i = 1 << ((buf[10] & 7) + 1) == 256 ? 256 : 0;
}
for (; i != 0; i--) {
fin.Read(buf, 0, 3);
if ((buf[0] == R) && (buf[1] == G) && (buf[2] == B)) {
transparentIdx = (byte)(256 - i);
}
fout.Write(buf, 0, 3);
}
bool gcePresent = false;
while (true) {
fin.Read(buf, 0, 1);
fout.Write(buf, 0, 1);
if (buf[0] != 0x21) break;
fin.Read(buf, 0, 1);
fout.Write(buf, 0, 1);
gcePresent = (buf[0] == 0xf9);
while (true) {
fin.Read(buf, 0, 1);
fout.Write(buf, 0, 1);
if (buf[0] == 0) break;
count = buf[0];
if (fin.Read(buf, 0, count) != count) return null;
if (gcePresent) {
if (count == 4) {
buf[0] |= 0x01;
buf[3] = transparentIdx;
}
}
fout.Write(buf, 0, count);
}
}
while (count > 0) {
count = fin.Read(buf, 0, 1);
fout.Write(buf, 0, 1);
}
fin.Close();
fout.Flush();
return new Bitmap(fout);
}
public void ProcessRequest(HttpContext context) {
Bitmap transGif = null;
using (Bitmap bmp = new Bitmap(300, 50)) {
using (Graphics g = Graphics.FromImage(bmp)) {
g.Clear(Color.Gray);
g.DrawString("transparent gif image",
new Font("verdana bold", 14f), Brushes.LemonChiffon, 0f, 0f);
bmp.MakeTransparent(Color.Gray);
transGif = MakeTransparentGif(bmp, Color.Black);
}
}
if (transGif != null) {
context.Response.Clear();
context.Response.ContentType = "image/GIF";
transGif.Save(context.Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Gif);
}
}
public bool IsReusable {get {return false;}}
}

測試html文件如下

復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body style="background:#999">
<img src="gif.ashx" style="position:absolute" />下方的文字
</body>
</html>

AspNet技術asp.net 動態輸出透明gif圖片,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 我半夜摸妺妺的奶C了她 | 夜色女人香 | 在教室伦流澡到高潮H女攻视频 | 国产看黄网站又黄又爽又色 | 邪恶肉肉全彩色无遮琉璃神社 | 日本久久久久亚洲中字幕 | 国产午夜三级一区二区三 | 国产精品久久久久久久久99热 | XXOO麻豆国产在线九九爱 | 99久久亚洲综合精品 | 美女张开腿露出尿口扒开来摸动漫 | 天堂Av亚洲欧美日韩国产综合 | 老色69久久九九精品高潮 | 扒开美女的内衣亲吻漫画 | 久久99热这里只频精品6 | 亚洲精品无码久久久久A片 亚洲精品无码国产爽快A片百度 | 仓井空torrent | 国产在线自天天人人 | 蜜芽手机在线观看 | 国产色精品久久人妻无码 | 消息称老熟妇乱视频一区二区 | 国产高清视频在线播放www色 | 野花韩国在线观看 | 香蕉99久久久久成人麻豆 | 美女内射少妇三区五区 | 日本国产成人精品无码区在线网站 | 日本亚洲中文字幕无码区 | 日本一二三区视频在线 | 美女扒开腿让男人桶个爽 | 99re久久热免费视频 | 看美女大腿中间的部分 | 久久久久久久久女黄 | 俄罗斯XX性幻女18 | 国产精品资源网站在线观看 | 综合一区无套内射中文字幕 | 国产免国产免费 | 四虎影院2022 | 国产国语在线播放视频 | 久久精品九九亚洲精品天堂 | 黑色丝袜美腿美女被躁翻了 | 男人舔女人的阴部黄色骚虎视频 |