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
C#
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;
namespaceRedDotAnnotate
{
publicpartialclassForm1 : Form
{
publicForm1()
{
InitializeComponent();
}
Bitmap OriginalImage;
Point myPts = Point.Empty;
privatevoidbutton1_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;
}
privatevoidpictureBox1_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();privatevoidpictureBox1_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);
}
}
}
}
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Gomathi PalaniswamyRank #714 · 3.3K reputationPosted Aug 17, 2010, 1:56 AM EDT
0
Hi friend,
Use the below code will help to draw ellipse on picturebox,
Gomathi PalaniswamyRank #714 · 3.3K reputationPosted Aug 17, 2010, 1:56 AM EDT
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
Noor Aznimah Abdul Aziz25 reputationPosted Aug 17, 2010, 7:52 PM EDT
thanks for the code, but can you explain more, which code placing too,
thanks
Aznimah