探索用户控件与图形绘制:GDI+、图表控制与图像优化
1. GDI+ 绘图基础
1.1 资源释放
在使用 GDI+ 完成图像绘制后,需要显式释放图像和图形上下文,因为它们持有一些非托管资源,如果不释放,这些资源可能不会立即被释放。示例代码如下:
g.Dispose()
image.Dispose()
1.2 绘制自定义图像
使用 GDI+ 可以轻松创建一个简单的网页,以下是一个示例代码,它使用 GDI+ 在带边框的矩形中绘制一些文本,并在旁边添加一个笑脸图形:
Protected Sub Page_Load(sender As Object, _
e As System.EventArgs) Handles Me.Load
' Create an in-memory bitmap where you will draw the image.
' The Bitmap is 300 pixels wide and 50 pixels high.
Dim image As New Bitmap(300, 50)
' Get the graphics context for the bitmap.
Dim g As Graphics = Graphics.FromImage(image)
' Draw a solid yellow rectangle with a red border.
g.FillRectangle(Brush
超级会员免费看
订阅专栏 解锁全文

92

被折叠的 条评论
为什么被折叠?



