代碼 復制代碼 代碼如下: //存成gif.ashx <%@ WebHandler Language="C#" Class="Gif" %> using System.IO; using Syste " /> 国产日产精品一区二区三区的介绍,中国一级黄色,午夜av片

四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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圖片,轉載需保留來源!

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

主站蜘蛛池模板: 电影哪吒闹海| 黑木美纱| 田教授的28个保姆演员表| 乱世伦情 电影| 演员李崇霄的个人资料| 极度险情| 康熙微服私访记第三部| 最美表演| 天与地越南版| 电影你不要走| 夜之女王 电影| 罗素克劳主演电影| 服务群众方面整改成效| 搞黄色的视频| 抖音网页版登录| 姐妹们| 醉翁亭记理解性默写及答案| 祖卡尔| 小兰花现代诗| 戚继光电影| 培根《谈读书》原文及翻译| 黄色网址在线播放| 龙的新娘电视剧全集| 朝雪录电视剧免费观看全集完整版| 变形金刚6免费完整版在线观看| 真实游戏在线| 报团云南旅游价格| 黑帮大佬365日| 吸痰护理ppt课件| 美女网站视频免费黄| 姐姐姐| 美丽的草原我的家二胡独奏| 发型男2024流行发型图片| 《高校教师》日本电影| 社会主义道德原则| 杰克逊·拉斯波恩| 卢昱晓电视剧| 婚后三十年电视剧剧情介绍| 成人免费黄色电影| 我的冠军男友在线看全集完整| 我在皇宫当巨巨|