绘制到画布而不考虑 DPI
我正在开发一个简单的街机游戏,我想将图形绘制到画布上,而不考虑设备 DPI,只考虑像素。 如果我在 240x320 像素模拟器中进行一些绘图,我希望画布具有 240x320 像素。 Canvas.getWidth()
和 getHeight()
告诉我,我有 240x320 像素的 Canvas,但是当我通过 g.drawLine(0,0, 240, 320, activePaint);
一条线仅绘制到 (180;240)。它以某种方式按 DPI 缩放,但我想绘制精确的像素。有一个简单的解决办法吗?谢谢
I'm developing a simple arcade game and I'd like to paint the graphics onto a Canvas without regard for the device DPI, just the pixels.
If I do some drawing in 240x320 pixels emulator, I'd like the Canvas to have 240x320 pixels.Canvas.getWidth()
and getHeight()
tell me that I have 240x320 pixels Canvas, but when I draw a line by g.drawLine(0,0, 240, 320, activePaint);
a line gets drawn only to (180;240). It's scaled by DPI somehow, but I'd like to draw to the exact pixels. Is there a simple fix to this? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的问题,那么你需要做的就是在你的清单中指定supports-screensanyDensity=true和smallScreens=true。这应该会阻止缩放的发生。
详细信息在这里: http://developer.android.com/guide/主题/清单/supports-screens-element.html
If I understand your question correctly then all you should need to do specify the supports-screens anyDensity=true and smallScreens=true into your manifest. That should stop the scaling from happening.
details here: http://developer.android.com/guide/topics/manifest/supports-screens-element.html