vb.net中使用GDI画图,然后平移,可是平移之前的图还在,怎么去掉平移之前的,保留平移之后的?

2025-03-09 12:14:26
推荐回答(2个)
回答1:

如果是简单的移动,先把图形绘制到大小和PictureBox的Bitmap上,然后再绘制到PictureBox就行。
不过在VB.NET中用GDI绘制最好用BufferedGraphics图形缓冲区,速度马马虎虎(VB就这样了),但是不闪烁,不存在背景擦除的问题。

回答2:

用覆盖的方法,再声明一个pen,颜色为picturebox1.backcolor。 我这里就把图片背景当成白色。
Dim ag As Graphics
Dim pen1 As New Pen(Color.FromArgb(255, 255, 255, 255), 2)
ag = PictureBox1.CreateGraphics
Dim rect As New Rectangle(0, 0, 50, 50)
Dim pen As New Pen(Color.FromArgb(255, 200, 0, 200), 2)
ag.DrawRectangle(pen, rect)
ag.DrawRectangle(pen1, rect)
ag.TranslateTransform(150, 50)
ag.DrawRectangle(pen, rect)