1

現在、ECG 波形を描画できるプログラムを開発しています。ECG 波形の速度は 25 mm/秒です。したがって、ピクセルをミリメートルに変換する必要があります。

ここで、C# を使用して画面サイズをミリメートル単位で取得したいと考えています。現在、2 台のモニターがあり、すべてのモニターの画面サイズを知りたいと思っています。サイズをピクセル単位で取得する方法は知っていますが、ミリメートル値を取得する方法はわかりません。

グーグルで検索したところ、WMI を使用すると画面サイズを取得できることがわかり、試してみましたが失敗しました。誰か私にいくつかの提案をしてもらえますか?

4

2 に答える 2

4

画面のサイズをミリメートル単位で取得するためのコードがstackoverflowで見つかりました。WMI を使用して画面を列挙し、デバイス ID を取得します。デバイス ID を使用して、レジスタ テーブルから EDID を取得します。次に、「edid」配列の項目 21、22 を読み取り、画面の幅と高さをミリメートル単位で取得します。

    public static List<PointF> GetDesktopMonitors()
    {
        List<PointF> screenSizeList = new List<PointF>();

        //////////////////////////////////////////////////////////////////////////

        try
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM WmiMonitorID");

            foreach (ManagementObject queryObj in searcher.Get())
            {
                Debug.WriteLine("-----------------------------------------------");
                Debug.WriteLine("WmiMonitorID instance");
                Debug.WriteLine("----------------");
           //   Console.WriteLine("Active: {0}", queryObj["Active"]);
                Debug.WriteLine("InstanceName: {0}", queryObj["InstanceName"]);
           //   dynamic snid = queryObj["SerialNumberID"];
           //   Debug.WriteLine("SerialNumberID: (length) {0}", snid.Length);
                Debug.WriteLine("YearOfManufacture: {0}", queryObj["YearOfManufacture"]);

                /*
                foreach (PropertyData data in queryObj.Properties)
                {
                    Debug.WriteLine(data.Value.ToString());
                }
                */

                dynamic code = queryObj["ProductCodeID"];
                string pcid = "";
                for (int i = 0; i < code.Length; i++)
                {
                    pcid = pcid + Char.ConvertFromUtf32(code[i]);
                  //pcid = pcid +code[i].ToString("X4");
                }
                Debug.WriteLine("ProductCodeID: " + pcid);


                int xSize = 0;
                int ySize = 0;
                string PNP = queryObj["InstanceName"].ToString();
                PNP = PNP.Substring(0, PNP.Length - 2);  // remove _0
                if (PNP != null && PNP.Length > 0) 
                {
                    string displayKey = "SYSTEM\\CurrentControlSet\\Enum\\";
                    string strSubDevice = displayKey + PNP + "\\" + "Device Parameters\\";
                    // e.g.
                    // SYSTEM\CurrentControlSet\Enum\DISPLAY\LEN40A0\4&1144c54c&0&UID67568640\Device Parameters
                    // SYSTEM\CurrentControlSet\Enum\DISPLAY\LGD0335\4&1144c54c&0&12345678&00&02\Device Parameters
                    //
                    Debug.WriteLine("Register Path: " + strSubDevice);

                    RegistryKey regKey = Registry.LocalMachine.OpenSubKey(strSubDevice, false);
                    if (regKey != null)
                    {
                        if (regKey.GetValueKind("edid") == RegistryValueKind.Binary)
                        {
                            Debug.WriteLine("read edid");

                            byte[] edid = (byte[])regKey.GetValue("edid");

                            const int edid_x_size_in_mm = 21;
                            const int edid_y_size_in_mm = 22;
                            xSize = ((int)edid[edid_x_size_in_mm] * 10);
                            ySize = ((int)edid[edid_y_size_in_mm] * 10);
                            Debug.WriteLine("Screen size cx=" + xSize.ToString() + ", cy=" + ySize.ToString());
                        }
                        regKey.Close();
                    }
                }

                Debug.WriteLine("-----------------------------------------------");

                PointF pt = new PointF();
                pt.X = (float)xSize;
                pt.Y = (float)ySize;

                screenSizeList.Add(pt);
            }
        }
        catch (ManagementException e)
        {
            Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
        }

        return screenSizeList;
    }
于 2013-06-10T04:29:09.107 に答える
-1

以下のリンクを参照してください。

http://www.dallinjones.com/2008/07/how-to-convert-from-pixels-to-millimeters/

C#でピクセルをインチに、またはその逆に変換する

于 2013-05-31T10:20:30.200 に答える