i'm trying to draw pixels in red color while moving the mouse so where the mouse cursor is inside the pictureBox1 draw at that point a pixel.
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();
}
this is very slow and not drawing pixels in red.
This is working in the mouse move event:
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.