在C#中使用GDI(Graphics Device Interface)可以通过System.Drawing命名空间中的类来实现。下面是一些使用GDI绘图的常见操作示例:
- 创建Graphics对象:
Graphics g = this.CreateGraphics();
- 绘制直线:
Pen pen = new Pen(Color.Black); g.DrawLine(pen, x1, y1, x2, y2);
- 绘制矩形:
Pen pen = new Pen(Color.Black); g.DrawRectangle(pen, x, y, width, height);
- 绘制椭圆:
Pen pen = new Pen(Color.Black); g.DrawEllipse(pen, x, y, width, height);
- 绘制文本:
Font font = new Font("Arial", 12); SolidBrush brush = new SolidBrush(Color.Black); g.DrawString("Hello World", font, brush, x, y);
- 绘制图像:
Image image = Image.FromFile("image.jpg"); g.DrawImage(image, x, y, width, height);
以上只是一些简单的示例,GDI还提供了更多绘图和图形处理的功能,你可以根据需要进一步研究和使用。