Pixel in cm?

  • Hallo,

    kennt jemand von euch villeicht eine Formel, mit der man aus der Pixelanzahl und dpi errechnen kann, wieviele Pixel einem Zentimeter auf einem Bildschirm entsprechen? Ich hab' mal gegoogelt, dort hab ich leider nur zahlreiche Umrechnungsprogramme gefunden, aber keine Formel!

    Einmal editiert, zuletzt von xp_fan (24. November 2009 um 19:01)

    • Offizieller Beitrag

    Dazu hatte ich mal eine Funktion geschrieben:

    Spoiler anzeigen
    [autoit]


    $dpi = _GetLogPixels()
    MsgBox(0, '', 'Monitorgröße (ca.): ' & Round(@DesktopWidth / ($dpi / 2.54), 2) & ' x ' & Round(@DesktopHeight / ($dpi / 2.54), 2) & ' cm²')

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetLogPixels()
    Local $LogPixels
    Local $objWMIService = ObjGet('winmgmts:\\localhost\root\CIMV2')
    Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_DisplayConfiguration', 'WQL', 0x30)
    If IsObj($colItems) then
    For $objItem In $colItems
    $LogPixels = $objItem.LogPixels
    Next
    Return $LogPixels
    Endif
    Return SetError(1, 0, 0)
    EndFunc

    [/autoit]

    Edit: Ach herrje, was bin ich heute wieder langsam... :whistling:

  • Ich hab' mal ein Mini-Maus-O-Meter daraus gemacht:

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $c = 0
    GUICreate("Mouse Meter", 300, 20, 852, 0, $WS_POPUPWINDOW, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
    $Label1 = GUICtrlCreateLabel('Die Maus hat bisher 0 Zentimeter zurückgelegt!', 0, 0, 300, 20)
    $dpi = _GetLogPixels()

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetLogPixels()
    Local $LogPixels
    Local $objWMIService = ObjGet('winmgmts:\\localhost\root\CIMV2')
    Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_DisplayConfiguration', 'WQL', 0x30)
    If IsObj($colItems) Then
    For $objItem In $colItems
    $LogPixels = $objItem.LogPixels
    Next
    Return $LogPixels
    EndIf
    Return SetError(1, 0, 0)
    EndFunc ;==>_GetLogPixels
    GUISetState(@SW_SHOW)
    AdlibEnable("MouseUpdate", 10)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    AdlibDisable()
    Exit
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func MouseUpdate()
    $pos = MouseGetPos()
    $x1 = $pos[0]
    $y1 = $pos[1]
    Sleep(10)
    $pos2 = MouseGetPos()
    $x2 = $pos2[0]
    $y2 = $pos2[1]
    $a = Sqrt(($x2 - $x1) ^ 2 + ($y2 - $y1) ^ 2)
    $b = Round($a, 0)
    $c = $c + $b
    $cm = Round($c / $dpi * 2.54, 0)
    GUICtrlSetData($Label1, "Die Maus hat ungefähr " & $cm & " Zentimeter zurückgelegt!")
    EndFunc ;==>MouseUpdate

    [/autoit]
    • Offizieller Beitrag

    Du lernst wirklich schnell. :thumbup:
    Eine kleine Änderung an Deinem Script und das Flackern verschwindet:

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $c = 0, $old = 0
    GUICreate("Mouse Meter", 300, 20, 852, 0, $WS_POPUPWINDOW, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
    $Label1 = GUICtrlCreateLabel('Die Maus hat bisher 0 Zentimeter zurückgelegt!', 0, 0, 300, 20)
    $dpi = _GetLogPixels()

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetLogPixels()
    Local $LogPixels
    Local $objWMIService = ObjGet('winmgmts:\\localhost\root\CIMV2')
    Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_DisplayConfiguration', 'WQL', 0x30)
    If IsObj($colItems) Then
    For $objItem In $colItems
    $LogPixels = $objItem.LogPixels
    Next
    Return $LogPixels
    EndIf
    Return SetError(1, 0, 0)
    EndFunc ;==>_GetLogPixels
    GUISetState(@SW_SHOW)
    AdlibEnable("MouseUpdate", 10)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    AdlibDisable()
    Exit
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func MouseUpdate()
    $pos = MouseGetPos()
    $x1 = $pos[0]
    $y1 = $pos[1]
    Sleep(10)
    $pos2 = MouseGetPos()
    $x2 = $pos2[0]
    $y2 = $pos2[1]
    $a = Sqrt(($x2 - $x1) ^ 2 + ($y2 - $y1) ^ 2)
    $b = Round($a, 0)
    $c = $c + $b
    If $c = $old Then Return
    $old = $c
    $cm = Round($c / $dpi * 2.54, 0)
    GUICtrlSetData($Label1, "Die Maus hat ungefähr " & $cm & " Zentimeter zurückgelegt!")
    EndFunc ;==>MouseUpdate

    [/autoit]