当前注册人数422815人 邮箱: 密码: 注册新用户 忘记密码
首页 C/C++/MFC C# ASP.NET VB.NET MATLAB Android   站内搜索 下载代码说明/积分规则
为什么要注册?

1. 可以直接免费从本站下载代码,防止邮件发送不到您的邮箱,或登录不了国外网站

2. 可以设定关键字,当有您关心的代码收录时,邮件通知您

3. 对这里的代码进行评分和评论

4. 可以和大家一起分享你的源代码,得到更多的建议

ASP.NET Transparent GIF Source Code

ASP.NET直接写透明GIF图像到输出流源代码

2008年03月04日
C#, C# 2.0, Windows, .NET, .NET 2.0, ASP.NET, VS, WebForms, VS2005, Dev
写图片到HTTP-Response输出流是非常简单的,不过写一个透明的GIF图像到输出流就比较困难了。这个程序,在ASP.NET中使用C#语言先创建调色板,然后改变所有Alpha值到0,这时候才会透明GIF中的透明颜色。
相关知识
System.Drawing.Image _gifImage;

        _gifImage = System.Drawing.Image.FromFile(Server.MapPath("white.JPG"));
        Bitmap bm = new Bitmap(_gifImage.Width, _gifImage.Height, 
                PixelFormat.Format8bppIndexed);

        // Get the palette from the bitmap
        ColorPalette pal = bm.Palette;

        // Set Alpha to 0
        for (int i = 0; i < pal.Entries.Length; i++)
        {
            Color col = pal.Entries[i];
            pal.Entries[i] = Color.FromArgb(0, col.R, col.G, col.B);
        }

        // assign palette
        bm.Palette = pal;

        //to copy the bitmap data we need to lock the source & 

    //destination bits
        BitmapData src = ((Bitmap)_gifImage).LockBits(new Rectangle
        (0, 0, _gifImage.Width, _gifImage.Height), ImageLockMode.ReadOnly,
         _gifImage.PixelFormat);
        BitmapData dst = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), 
        ImageLockMode.WriteOnly, bm.PixelFormat);

        //finished, unlock the bits
        ((Bitmap)_gifImage).UnlockBits(src);
        bm.UnlockBits(dst);
        
        //Set Response Type to "image/gif"
        Response.ContentType = "image/gif";

        //Writing the gif directly into the Output-Stream
        bm.Save(Response.OutputStream, ImageFormat.Gif);

        //cleaning up
        bm.Dispose();
        _gifImage.Dispose();

        //Send output stream
        Response.Flush();
源代码原文下载:
ASP.NET Transparent GIF Writing a transparent gif directly into the output stream via ASP.NET & C#

源码图片

点击链接查看大图
从本站下载附件及源代码(1个附件,已经成功下载102次)

最值得关注的外文源代码

Openbravo ERP
Fading Forms In and Out
Transparent Desktop Video
Free Source Code for Using a Control Adapter to Properly Display PNG Images in IE
评论(评论是增加积分的一个有效途径)
字数在300字内
请如实评论
本源代码共评论20次,此处显示最近12次评论! 查看所有评论

yndxstxy2010jrsx  2015年10月23日
kankana
刚哥  2014年06月17日
kankan
情缘  2011年12月14日
谢谢,学习了
combox  2009年07月18日
不错啊~!找了好久
as4412  2009年06月13日
不错啊~!找了好久
kingmaohappy  2009年05月17日
ASP.NET直接写透明GIF图像到输出流源代码
ss_geng  2008年12月14日
ok
小刚  2008年11月11日
heihie
spring  2008年11月04日
ss
K+F  2008年10月22日
ASP.NET直接写透明GIF图像到输出流源代码
ctgu0001  2008年10月19日
lry  2008年08月28日
ASP.NET直接写透明GIF图像到输出流源代码
字数在300字内
请如实评论
200万国内源码搜索
CopyRight (C) codesoso.com 2007-2009 All Rights Reserved zhihuishi   免责声明