[英]How can i make that when i move the mouse ober pictureBox1 it will draw points automatic on pictureBox2?
[英]How to draw pixels in color red on the image in pictureBox1 in real time on mouse move event?
我正在尝试在移动鼠标时以红色绘制像素,以便鼠标 cursor 在 pictureBox1 内部绘制一个像素。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
pictureBox1.Image = Properties.Resources._image;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
label1.Text = String.Format("X: {0}; Y: {1}", e.X, e.Y);
Bitmap bmp = new Bitmap(pictureBox1.Image);
for(int x = 0; x < bmp.Width; x++)
{
for(int y = 0; y < bmp.Height; y++)
{
bmp.SetPixel(e.X, e.Y, Color.Red);
}
}
bmp.Dispose();
}
这非常慢,并且不会以红色绘制像素。
这在鼠标移动事件中起作用:
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
label1.Text = String.Format("X: {0}; Y: {1}", e.X, e.Y);
Bitmap bmp = new Bitmap(pictureBox1.Image);
bmp.SetPixel(e.X, e.Y, Color.Red);
pictureBox1.Image = bmp;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.