HI,
i need help on how to draw a square dot when fire mouse click:
-onto image in picturebox
-the dot size is 10px X 10px
-and return the position of dots (x,y) values.
here i try some code but missing in somewhere, please help me,
thanks
Regards
Aznimah
i need help on how to draw a square dot when fire mouse click:
-onto image in picturebox
-the dot size is 10px X 10px
-and return the position of dots (x,y) values.
here i try some code but missing in somewhere, please help me,
thanks
Regards
Aznimah
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace RedDotAnnotate
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Bitmap OriginalImage;
Point myPts = Point.Empty;
private void button1_Click(object sender, EventArgs e)
{
//Open File Dialog to load image files
openFileDialog1.FileName = "";
openFileDialog1.Title = "Images";
//Filter the filedialog, so that it will show only the mentioned format images
openFileDialog1.Filter = "PNG Image(*.png)|*.png|JPG Image(*.jpg)|*.jpg|BMP Image(*.bmp)|*.bmp";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName.ToString() != "")
{
pictureBox1.ImageLocation = openFileDialog1.FileName.ToString();
OriginalImage = new Bitmap(openFileDialog1.FileName.ToString());
}
// butSave.Enabled = true;
}
private void pictureBox1_mouseDown(object sender, MouseEventArgs e)
{
Point myPts = new Point(e.X, e.Y);
Bitmap b = (Bitmap)pictureBox1.Image;
Graphics g = Graphics.FromImage(b);
// myPts.add(new Point(e.X, e.Y));
Invalidate();
pictureBox1.Image = b;
}
// List<Point> myPts = new List<Point>();
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
foreach (Point p in myPts)
{
g.DrawEllipse(new Pen(Color.Green), p.X, p.Y, 10, 10);
}
}
}
}
Comment