ActionScript 屏幕测量
我试图使用 Capability 类在屏幕上以精确的 (2.5" x 5") 绘制精确大小的精灵,而不管屏幕的分辨率如何,但是虽然我相信代码是正确的,但精灵的大小并不准确 -实际用尺子测量时。
function inchesToPixels(inches:Number):uint
{
return Math.round(Capabilities.screenDPI * inches);
}
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0x000000, 0.5);
mySprite.graphics.drawRect(0, 0, inchesToPixels(2.5), inchesToPixels(5));
mySprite.graphics.endFill();
addChild(mySprite);
i'm attempting to use the Capabilities class to draw an accurately sized sprite on screen at exactly (2.5" x 5") regardless of the screen's resolution, but while i believe the code is correct, the size of the sprite is not accurate - when actually measuring it with a ruler.
function inchesToPixels(inches:Number):uint
{
return Math.round(Capabilities.screenDPI * inches);
}
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0x000000, 0.5);
mySprite.graphics.drawRect(0, 0, inchesToPixels(2.5), inchesToPixels(5));
mySprite.graphics.endFill();
addChild(mySprite);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对此并不完全确定,但我的感觉是,对于运行相同分辨率的两个显示器,Capability 类返回的 screenDPI 值将是相同的值,即使显示器具有不同的物理尺寸。
举例来说,如果您有两台显示器,一台为 14 英寸,另一台为 28 英寸,两者都显示相同的 800 x 600 像素分辨率,则 screenDPI 属性将返回相同的值,因为它们都使用相同的分辨率。
然而,由于显示器的物理尺寸,每个屏幕上实际的实际英寸的点数会有所不同。因此,当您运行代码并使用尺子测量您创建的屏幕精灵时,它不会与现实世界的英寸相匹配。我不确定你如何解决这个问题(如果我对造成这个问题的原因是正确的),这似乎很困难。
德布
I'm not entirely sure about this, but my feeling is that the screenDPI value being returned by the Capabilities class would be the same value for two monitors running the same resolution, even if the monitors had different physical dimensions.
To illustrate, if you have two monitors, one which is 14" and the other which is 28", both displaying the same resolution of 800 x 600 pixels, that screenDPI property will return the same thing because they're both using the same resolution.
However, the number of dots in a literal, real-world inch on each screen will be different because of the physical dimensions of the monitor. So when you're running your code and measuring the on-screen Sprite you create with a ruler, it's not going to match up to real-world inches. I'm not sure how you could get around this problem (if I'm right about what's causing it), it seems like it'd be difficult.
Debu
我建议在您的应用程序开始时告诉用户“我检测到您的显示器是 XX 英寸”(其中 XX 是根据 screenDPI 计算得出的),并允许用户输入正确的显示器尺寸。
I suggest at the start of your app telling the user "I detected your monitor is XX inches" (where XX is calculated from screenDPI), and allow the user to type in a correct monitor size.