如何获得具有精确分辨率的float或double鼠标位置? [英] How to get mouse position in float or double with exact resolution?

查看:161
本文介绍了如何获得具有精确分辨率的float或double鼠标位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将鼠标单击位置设置为float或double,如何做到这一点?在鼠标侦听器中,我要像这样,

I need to take the mouse click position in float or double, how can I do that?In mouse listener, I take the point like this,

e.getPoint();

但是Point对象的x和y值是整数,我需要在float或double中定位. 任何帮助将不胜感激.

but Point object's x and y values are integer, I need position in float or double. Any help will be appreciated.

修改 我需要确切的分辨率.

推荐答案

getPoint()为您提供整数值,因为这是指定坐标的精度.请参见 http://java.sun.com /j2se/1.4.2/docs/api/java/awt/Point.html .

getPoint() gives you integer values because that is the precision in which coordinates are specified. See http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Point.html.

为什么需要浮点值?

编辑:为了回应您的评论,您需要使用地板(始终向下舍入)或舍入(舍入到最接近的整数)等函数将绝对位置映射到屏幕上的像素.系统没有0.2像素或类似像素的概念.您可以连续截断计算的小数部分,也可以始终保持精确的坐标,然后根据需要将其映射到像素.

Edit: in response to your comment, you will need to map your absolute positions to onscreen pixels, using a function like floor (always round down) or round (round to nearest int). The system has no notion of 0.2 pixels or anything like that. You can either continually truncate the decimal part of your calculations, or maintain the exact coordinates at all times and map them to pixels as needed.

这篇关于如何获得具有精确分辨率的float或double鼠标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆