免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
C# 生成透明Gif圖片

C#中生成透明Gif文件

在C#中使用Graphics.Clear(Color.Transparent)生成gif格式透明文件時(shí),設(shè)置透明不起作用。使用Bitmap.MakeTransparent 方法同樣也不能使gif文件透明。這兩個(gè)問題也是微軟的設(shè)計(jì)使然,和gif文件格式有關(guān)系。

如果要在c#中編程實(shí)現(xiàn)透明色,必須另寫代碼,下面是一位老外的代碼

-->///

/// Make the image transparent.

/// The input is the color which you want to make transparent.

///

///The color to make transparent.

///The bitmap to make transparent.

///New memory stream containing transparent background gif.

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

}

在生成圖片之后調(diào)用此方法,即可使gif顯示透明色。

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
USACO/concom
哈弗曼壓縮實(shí)例(一)
使用openssl中的加密函數(shù)AES、RC4、RSA對(duì)文件加密的一個(gè)例子
UTF-8, UTF-16, UTF-16LE, UTF-16BE的區(qū)別
java學(xué)習(xí)札記(15)-Scanner用法詳細(xì)
android 文件操作
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服