Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have values of x and y coordinates in my database. On the button click event, I want to display a small dot on the image for those coordinates. e.g. The values that I have for x and y coordinates are like this:

HTML
XLoc    YLoc
0.78    -3.22
1.6     -5.02
1.29    -5.71
1       -2.26
0.6     -2.11


and so on....

What I have tried:

C#
private void btnSetCoordinates_Click(object sender, EventArgs e)
      {
          try
          {
              Bitmap PicBox1 = new Bitmap(picImage.Image);

              ((Bitmap)picImage.Image).SetPixel(txtXloc.Text, txtYLoc.Text, Color.Black);
              picImage.Refresh();

          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
              throw;
          }

      }


When I try any negative value to set pixel on image, it throws an error. Can anyone please help me?
Posted
Updated 16-Jan-18 6:07am
v2
Comments
F-ES Sitecore 16-Jan-18 11:36am    
What do you want to happen when someone sets a pixel at a negative point?
webmail123 16-Jan-18 11:58am    
I didn't get you question.
I want to show the pixel on the given x and y coordinates. As of now I am getting error saying 'Parameter must be positive.'
F-ES Sitecore 16-Jan-18 12:04pm    
If an image is 100 pixels by 100 pixels then (0,0) is the upper left corner, (100, 0) the upper right, (0,100) the lower left and (100,100) the lower right, so where is -10, -10?
webmail123 16-Jan-18 13:24pm    
So that's where I need help with. I need to convert those coordinates into a actual coordinates which are compatible with 100px by 100px image.(its just an example)
F-ES Sitecore 17-Jan-18 4:16am    
You still haven't answered the question...on a 100x100 image where will -10,-10 appear? Until you know the answer to that question you can't write any code. You have to fully understand a problem before you can write code to solve it, you have to know the inputs and the outputs, so if the input is -10,-10 what is the output?

1 solution

Unfortunately the SetPixel documentation doesn't help. Anyway the GetPixel one[^] does:
ArgumentOutOfRangeException
x is less than 0, or greater than or equal to Width.

-or-

y is less than 0, or greater than or equal to Height.


Basically you cannot address negative coordinates. However you may transform your coordinates in order to fit the Bitmap box.
 
Share this answer
 
v3
Comments
webmail123 16-Jan-18 13:40pm    
Thanks for the answer. And I think the same. To transform coordinates in order to fit in bitmap box. Is there any inbuilt function for it?


Basically I have a laboratory layout and that layout has coordinates like this:

- top right corner of laboratory is considered as origin (0,0)
- bottom right corner is considered as (-1, -8.6)
- top left corner is considered as (4.2 , 0)
- bottom left corner is considered as (4.2, -8.6)
- definitely midpoints are (-1, -4.3) and (4.2, -4.3)


Now if any items coordinates are (0.78, -3.22) then I want to show a dot on the image to display location of that item.
Did you get my idea??
CPallini 20-Jan-18 5:34am    
Are you sure laboratory frame is not a rectangle?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900