Cordova:真正的硬件分辨率

时间:2016-04-13 13:55:17

标签: javascript android apache cordova

使用Apache Cordova我无法获得真正的设备分辨率。我希望我的应用程序/游戏全屏运行,并在我的HTC One m7上使用完整的1920 x 1080像素。我用以下方法检查我的决议:

window.innerWidth
window.innerHeight

...我得到640 x 480而不是全高清。我尝试使用< viewport ...>但没有运气。换句话说:有没有办法让Cordova app获得1:1的设备分辨率?

1 个答案:

答案 0 :(得分:0)

我猜测(不是100%肯定)你得到1:1,Cordova回归你的是dp(或dip - 密度独立像素)而不是px(CSS逻辑像素)。您可以尝试使用window.devicePixelRatio来获取转换率以获得逻辑像素。即。尝试这样的事情:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace AutoClick
{
    public partial class main : Form
    {
        [DllImport("user32.dll")]
        static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);

        [Flags]
        public enum MouseEventFlags
        {
            LEFTDOWN = 0x00000002,
            LEFTUP = 0x00000004,
            MIDDLEDOWN = 0x00000020,
            MIDDLEUP = 0x00000040,
            MOVE = 0x00000001,
            ABSOLUTE = 0x00008000,
            RIGHTDOWN = 0x00000008,
            RIGHTUP = 0x00000010
        }

        public static void LeftClick(int x, int y)
        {
            Cursor.Position = new System.Drawing.Point(x, y);
            mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
            mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
        }

        public main()
        {
            InitializeComponent();
        }

        private void main_Load(object sender, EventArgs e)
        {
            LeftClick(this.Location.X + 300, this.Location.Y + 250);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Text = "Ok";
        }
    }
}

此外,如果您在meta(标题)target-densitydpi = device-dpi中有此功能,请尝试将其删除。