开发者

Overlaying a 'dot' on to an image on click

开发者 https://www.devze.com 2023-01-18 01:04 出处:网络
I am trying to write a simple program that lets me overlay a dot on top of an image when the image is clicked.I can save the X and Y data back to my database but then I will want to be able to call th

I am trying to write a simple program that lets me overlay a dot on top of an image when the image is clicked. I can save the X and Y data back to my database but then I will want to be able to call that information back at a later date and overlay the dots again via code unlike the first time when the user had to click the image.

I got as far as capturing the X and Y of the click no problem but I am having trouble finding examples specifically for what I am trying to do. All of the examples online seem to be for saving the image with the added graphic but I do not need to do that as it will be the same image every time.

Once I can do this, I also need to work out a way that I can detect what area of the image has been clicked. The areas I need to mark out vary in shape and size so I need to try and work out a way to 'map' these areas and then cross referenc开发者_JS百科e with the co-ordinates of the users click (I assume that I may need to do some clever geometry stuff for that?)

If anyone has any suggestions of what subjects/classes/methods etc. to research for either of my queries, I would very grateful.

Thanks in advance


You can use the System.Drawing namespace to achieve this.

Create a control and override OnPaint and OnPaintBackground. Store your clicks in a List

  • In OnPaintBackground, draw the image using DrawImageUnscaled using the graphics object which is passed to you as a parameter.

  • In OnPaint, loop through your points array and call graphics.FillElipse or similar to draw a little dot.

Because this isnt a retained mode graphics system, you need to keep drawing these items so this may not suit a large number of dots. In that case, you can create an in memory bitmap and get a graphics drawing object using graphics.FromImage.

0

精彩评论

暂无评论...
验证码 换一张
取 消