如何绘制图像的一行? [英] how to draw a line on a image?
问题描述
我要画一个BMP图像是传递到方法在C#中使用的DrawLine方法就行
i want to draw a line on a bmp image which is pass into a method using drawline method in C#
public void DrawLineInt(Bitmap bmp)
{
Pen blackPen = new Pen(Color.Black, 3);
int x1 = 100;
int y1 = 100;
int x2 = 500;
int y2 = 100;
// Draw line to screen.
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2);
}
这给了我error.So想知道如何在这里包括油漆事件
(PaintEventArgs的E)
this give a error.So i want to know how to include paint event here (PaintEventArgs e )
和也想知道如何传递参数的时候,我们调用drawmethod?
例如:
and also want to know how to pass parameters when we calling drawmethod? example
DrawLineInt(Bitmap bmp);
这给下面的错误
这个名字的'e'并不在目前情况下存在
this give the following error "The name 'e' does not exist in the current context "
推荐答案
画一个BMP图像是传递到方法在C#中使用的DrawLine方法上一行
"Draw a line on a bmp image which is pass into a method using drawline method in C#"
PaintEventArgs的Ë会建议您在画图事件的对象时这样做。既然你是在方法调用这一点,那么你没有不需要添加任何地方PaintEventArgs的如
PaintEventArgs e would suggest that you are doing this during the "paint" event for an object. Since you are calling this in a method, then no you do not need to add PaintEventArgs e anywhere.
要做到这一点的方法,使用@贝丽的回答。
To do this in a method, use @BFree's answer.
public void DrawLineInt(Bitmap bmp)
{
Pen blackPen = new Pen(Color.Black, 3);
int x1 = 100;
int y1 = 100;
int x2 = 500;
int y2 = 100;
// Draw line to screen.
using(var graphics = Graphics.FromImage(bmp))
{
graphics.DrawLine(blackPen, x1, y1, x2, y2);
}
}
当对象是重绘画图事件引发的。更多信息请参阅:
The "Paint" event is raised when the object is redrawn. For more information see:
<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint.aspx\">http://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint.aspx
这篇关于如何绘制图像的一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!