在C#中设置图像的负坐标 [英] Set negative coordinates for an image in C#
问题描述
我的数据库中有x和y坐标值。在按钮单击事件中,我想在图像上显示这些坐标的小点。例如我对x和y坐标的值是这样的:
XLoc YLoc
0.78 -3.22
1.6 -5.02
1.29 -5.71
1 -2.26
0.6 -2.11
等等on ....
我尝试过的事情:
< pre lang =c#> private void btnSetCoordinates_Click( object sender,EventArgs e)
{
try
{
Bitmap PicBox1 = new 位图(picImage.Image);
((位图)picImage.Image)。SetPixel(txtXloc.Text,txtYLoc.Text,Color.Black);
picImage.Refresh();
}
catch (例外情况)
{
MessageBox.Show(ex.Message);
throw ;
}
}
当我尝试任何负值设置像素时在图像上,它会抛出一个错误。任何人都可以帮助我吗?
不幸的是SetPixel
文档没有帮助。无论如何GetPixel
一个 [ ^ ]确实:
ArgumentOutOfRangeException
x小于0,或大于或等于宽度。
-or-
y小于0,或大于或等于高度。
基本上你不能解决负坐标。但是,您可以转换坐标以适合位图
框。
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:
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:
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?
Unfortunately theSetPixel
documentation doesn't help. Anyway theGetPixel
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 theBitmap
box.
这篇关于在C#中设置图像的负坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!