Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Way To Show "Points" on a pictureBox Image?

Status
Not open for further replies.

Insider1984

Technical User
Feb 15, 2002
132
US
Basically, I have a picture box which I would like to display "points" on it in one of two ways:

1. Prefered would be to draw an actual point on or on top of the picture box

2. Modify the image to change the pixel (do not want to do).

Also is there an easy way to get the scale factor of the image inside the picture box?

=====================
Insider
4 year 'on the fly' programmer
C, C++, C#, MFC, Basic, Java ASP.NET
 
You want to display points where the user clicks? Where do the points come from?

I think the graphics object can probably do what you want, but I don't know what it is you want.

And for the second question, I am fairly certain you can use PictureBox.Image.Size.Width and .Height in calculating this.

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
double xcompression = pictureBox1.Image.Width / pictureBox1.Width;

double ycompression = pictureBox1.Image.Height / pictureBox1.Height;


as for drawing - Alex is right. Define where you want to draw your points and use the graphics object when the picturebox redraws (capture the Paint event)

To force the pictureBox to redraw you can say pictureBox1.Invalidate(); which will fire the paint event.

as for drawing the points directly, you can draw anything from a simple dot to a full blown bitmap on top of your image...

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.FillEllipse(Brushes.Red, 10, 10, 3, 3);
//should draw a circle at the point 10,10 with a diameter of 3 pixels
}
 
Thanks. Last question, is there a way to remove the points I've already drawn but keep the pictureBox.Image in tact?

the only picture.CreateGraphics().Clear()

asks for a color and overrights the image (until resize etc)./

=====================
Insider
4 year 'on the fly' programmer
C, C++, C#, MFC, Basic, Java ASP.NET
 
just don't draw the dots on the next invalidate()


the best way to think of it is like this, everything drawn is in layers




------------ <- Your GDI+ Layer ("Points")
------------ <- The pictureBox.Image layer (the picture)
------------ <- The pictureBox background (default is "control" color


When you invalidate, the Image layer draws, then your layer draws if you choose.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top