加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 如何使用System.Drawing绘制透明图像?

发布时间:2020-12-15 23:08:14 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试从.aspx页面返回透明的GIF,以便在网页中显示.我试图让图像具有透明度,但是我只是不断地将黑色变成透明的图像. 有谁知道我做错了什么? Protected Sub Page_Load(ByVal sender As Object,ByVal e As System.EventArgs) _ Handles Me.Load '' Change
我正在尝试从.aspx页面返回透明的GIF,以便在网页中显示.我试图让图像具有透明度,但是我只是不断地将黑色变成透明的图像.

有谁知道我做错了什么?

Protected Sub Page_Load(ByVal sender As Object,ByVal e As System.EventArgs) _
  Handles Me.Load
    '' Change the response headers to output a GIF image.
    Response.Clear()
    Response.ContentType = "image/gif"

    Dim width = 110
    Dim height = width

    '' Create a new 32-bit bitmap image
    Dim b = New Bitmap(width,height)

    '' Create Grahpics object for drawing
    Dim g = Graphics.FromImage(b)

    Dim rect = New Rectangle(0,width - 1,height - 1)

    '' Fill in with Transparent
    Dim tbrush = New System.Drawing.SolidBrush(Color.Transparent)
    g.FillRectangle(tbrush,rect)

    '' Draw Circle Border
    Dim bPen = Pens.Red
    g.DrawPie(bPen,rect,365)

    '' Fill in Circle
    Dim cbrush = New SolidBrush(Color.LightBlue)
    g.FillPie(cbrush,365)


    '' Clean up
    g.Flush()
    g.Dispose()

    '' Make Transparent
    b.MakeTransparent()

    b.Save(Response.OutputStream,Imaging.ImageFormat.Gif)
    Response.Flush()
    Response.End()
End Sub

解决方法

不幸的是,使用Bitmap对象创建透明的Gif并不容易. (见 this KB article)

您也可以使用支持透明度的PNG格式与您正在使用的代码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读