hi,
i need help on to draw square on image when fire mouse click, basically like click down and mark the red dot with size of 10px x 10px,
the image would be in the picturebox. after draw the points, i need the position of the points.
here is some code that i try but missing in somewhere,
hopefully someone could help me on
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();
} // List myPts = new List();
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);
}
} }
}
|
Noor Aznimah Abdul AzizPosted Aug 17, 2010, 11:52 PM
thanks for the code, but can you explain more, which code placing too,
thanks
Aznimah
Gomathi PalaniswamyPosted Aug 17, 2010, 5:56 AM
Use the below code will help to draw ellipse on picturebox,
Graphics g=picturebox.creategraphics();
pen mypen=new pen(color.green,5);
rectangle myrec=new rectangle(20, 20, 250, 200);
g.drawellipse(mypen,myrec);
With Regards,
Gomathi.P