代碼 復(fù)制代碼 代碼如下: //存成gif.ashx <%@ WebHandler Language="C#" Class="Gif" %> using System.IO; using Syste " /> 日韩精品久久久,亚洲国产精品成人,国产精品久久久久久久久久久久久

中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

asp.net 動態(tài)輸出透明gif圖片

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

代碼
復(fù)制代碼 代碼如下:
//存成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文件如下

復(fù)制代碼 代碼如下:
<!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技術(shù)asp.net 動態(tài)輸出透明gif圖片,轉(zhuǎn)載需保留來源!

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

主站蜘蛛池模板: 国产成人高清视频 | 中文字幕亚洲免费 | 日韩中文在线 | 精品久久中文字幕 | 三级成人在线 | 久久久久国产一级毛片高清网站 | 成人免费在线观看 | 成人在线中文字幕 | 精品视频 免费 | 一区二区三区视频在线观看 | 狠狠天天 | 亚洲黄色在线免费观看 | 欧美黄色片 | 国产成人免费视频网站视频社区 | 96久久久久久 | 激情一区二区三区 | 日韩在线免费 | 激情黄色在线观看 | 男人天堂免费在线 | 国产精品夜色一区二区三区 | 成人免费在线视频 | 毛片一区二区 | 亚洲国产精品一区二区三区 | 91大神在线资源观看无广告 | 精品网| 精品九九九| 羞羞的视频免费观看 | 亚洲一区精品在线 | 国产污视频在线 | 在线超碰 | 精品国产欧美一区二区三区不卡 | 久久精品亚洲 | 99亚洲视频 | 久久伊人精品一区二区三区 | 成人性视频在线 | 综合自拍 | 国产精品久久国产精品 | av在线天堂 | 中文字幕在线观看视频网站 | 中文字幕精品一区二区三区精品 | 中文字幕高清在线 |