c# - 通过整数除法缩放一组坐标时丢失像素
问题描述
我正在尝试制作一个程序,将鼠标移动一定数量的像素。移动的坐标设置在“dx”和“dy”整数中,并取自整数数组,例如{ -85, 75 }, { 0, 67 }, { 33, 57 }, { 58, 48 }
等等 - 有很多这样的移动。
这些坐标的数组设置为鼠标灵敏度 =0,25
我需要做的是将其转换为等于鼠标灵敏度1
为了获得小 4 倍的移动,我尝试将我从数组 ( {-85, 75}
) 中得到的值(整数)除以 4。
整个问题是,当我划分时,假设-85 / 4
它给我留下了余数,这意味着我每次移动都会丢失像素。
它可以存储为双精度,但鼠标移动只能以整数表示,因为我们不能移动半个像素
有什么解决办法吗?如果我在每次拍摄时丢失 3 或 4 个像素,这没什么大不了的,但因为它越来越糟。
这是我的一段代码,可用于移动鼠标:
`
private void _MoveMouse()
{
while (appRunning)
{
if (Utility.bGetAsyncKeyState(Keys.LButton))
{
int[,] pattern = Current_Table().Item1; //Current_Table() returns table of (x, y) coordinates in integers and sleep time in integer that is used to sleep the thread
int sleep = Current_Table().Item2;
if (_ENABLED == true)
{
for (int i = 0; i < 30; i++)
{
int dx = pattern[i, 0]/4; //leaves a remainder from X coordinates that can not be stored in integer.
int dy = pattern[i, 1]/4; //leaves a remainder from Y coordinates that can not be stored in integer
int dx_rest = dx % 4; //the remainder from X
int dy_rest = dy % 4; //the remainder from Y
//MessageBox.Show(Convert.ToString(pattern[i,0] + " " + pattern[i,1]));
Utility.Move(dx, dy );
Thread.Sleep(sleep);
if (Utility.bGetAsyncKeyState(Keys.LButton)== false)
{
break;
}
}
}`
解决方案
推荐阅读
- java - 春季启动中的@ManyToMany关系?
- nginx - Nginx 重写 url 路径以添加路径前缀
- python - 线性组合python的递归
- python - 列表元素上的索引输出不正确 - Python
- python - 在python中比较一维和二维系列的有效方法
- hadoop - Hadoop put:意外的URISyntaxException
- javascript - 如何在 JavaScript 中将 [ ] 括号添加到 JSON
- spring - 在 Spring 反应式中聚合单声道
- css - 如何证明 CSS flex 是完整的或与 float 相同?
- python - 如何在熊猫中引用数组中的顺序值