在我的表单中只有一个图片框,我想用这个图片框上的方法绘制圆圈,但我不能这样做而不工作.方法是:
private Bitmap Circle() { Bitmap bmp; Graphics gfx; SolidBrush firca_dis=new SolidBrush(Color.FromArgb(192,0,192)); bmp = new Bitmap(40, 40); gfx = Graphics.FromImage(bmp); gfx.FillRectangle(firca_dis, 0, 0, 40, 40); return bmp; }
图片框
private void pictureBox2_Paint(object sender, PaintEventArgs e) { Graphics gfx= Graphics.FromImage(Circle()); gfx=e.Graphics; }
TaW.. 5
你需要决定你想做什么:
画入图像或
吸引控制?
你的代码是两者的混合,这就是为什么它不起作用.
下面是如何画上了Control
:
private void pictureBox1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawEllipse(Pens.Red, new Rectangle(3, 4, 44, 44)); .. }
下面是如何绘制成的Image
的PictureBox
::
void drawIntoImage() { using (Graphics G = Graphics.FromImage(pictureBox1.Image)) { G.DrawEllipse(Pens.Orange, new Rectangle(13, 14, 44, 44)); .. } // when done with all drawing you can enforce the display update by calling: pictureBox1.Refresh(); }
两种绘制方式都是持久的.后者改变为Image的像素,前者不是.
因此,如果像素被绘制到图像中并且您缩放,拉伸或移动图像,则像素将随之移动.绘制在PictureBox控件顶部的像素不会这样做!
当然,对于这两种方式来绘制,你可以改变所有常见的部件,如绘图命令,也许增加一个FillEllipse
之前DrawEllipse
,在Pens
和Brushes
他们的画笔类型,Colors
并且尺寸..
你需要决定你想做什么:
画入图像或
吸引控制?
你的代码是两者的混合,这就是为什么它不起作用.
下面是如何画上了Control
:
private void pictureBox1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawEllipse(Pens.Red, new Rectangle(3, 4, 44, 44)); .. }
下面是如何绘制成的Image
的PictureBox
::
void drawIntoImage() { using (Graphics G = Graphics.FromImage(pictureBox1.Image)) { G.DrawEllipse(Pens.Orange, new Rectangle(13, 14, 44, 44)); .. } // when done with all drawing you can enforce the display update by calling: pictureBox1.Refresh(); }
两种绘制方式都是持久的.后者改变为Image的像素,前者不是.
因此,如果像素被绘制到图像中并且您缩放,拉伸或移动图像,则像素将随之移动.绘制在PictureBox控件顶部的像素不会这样做!
当然,对于这两种方式来绘制,你可以改变所有常见的部件,如绘图命令,也许增加一个FillEllipse
之前DrawEllipse
,在Pens
和Brushes
他们的画笔类型,Colors
并且尺寸..