Bitmap erstellen mit Daten

  • Morgen,

    ich hab nun schon die SuFu genutzt und hin und her gegoogelt. Hab viel hin und her getestet.
    Ich komme aber zu keinem vernünftigen Ergebnis.

    Ich möchte eine Bitmap erstellen um die in GDI+ zu verwenden. Ich hab auch alles, Größe, Bittiefe, Kanäle und die Daten mit Hilfe eines Pointers.
    Wie kann ich nun mit dem ganzen eine Bitmap erstellen?

  • Ich würde mir mal den Wikipedia-Artikel ansehen. Da findest du eine komplette Beschreibung des BMP-Formats. Das ganze Nachzubauen sollte eigentlich nicht so ein grosses Problem sein. Musst ja nur noch alles in eine Variable packen. Wie du das Ganze dann In GDI+ verwendest kann ich dir aber auch nicht genau sagen. Vielleicht musst du es erst in eine Datei speichern.

    Gruss Shadowigor

  • Danke, aber das hilft mir auch nicht weiter.
    Hab nun hinbekommen, dass was angezeigt wird. Aber es ist transformiert???

    Spoiler anzeigen
    [autoit]

    #include "OpenCV.au3"
    #include <GDIPlus.au3>
    #include <WinAPIEx.au3>
    #include <GUIConstantsEx.au3>

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

    Global $tImage, $hGui, $hGraphics, $hBitmap, $hImage

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

    _OpenCV_Startup()
    $tImage = _OpenCV_LoadImage(@DesktopDir & "\Kamera Test.bmp")
    _OpenCV_Resize2($tImage, 20)

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

    $hGui = GUICreate("Test", 800, 600)
    GUISetState()

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

    _GDIPlus_Startup()

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

    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    $hBitmap = _CreateBitmapFromIplImage($tImage)
    $hImage =_GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage, 20, 20)

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

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    _Exit()
    EndSwitch
    WEnd

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

    Func _Exit()
    _OpenCV_ReleaseImage($tImage)
    _OpenCV_Shutdown()
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete()
    MsgBox(0, "", "Fertig")
    Exit
    EndFunc

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

    Func _CreateBitmapFromIplImage($_tIplImage)
    Local $_pBitmapBits
    Local $_iWidth = DllStructGetData($_tIplImage, "width")
    Local $_iHeight = DllStructGetData($_tIplImage, "height")
    Local $_iDepth = DllStructGetData($_tIplImage, "depth")
    Local $_iChannels = DllStructGetData($_tIplImage, "nChannels")
    Local $_pData = DllStructGetData($_tIplImage, "imageData")
    Local Const $_tagBITMAPINFOHEADER = 'dword biSize ;long biWidth;long biHeight;ushort biPlanes;ushort biBitCount;dword biCompression;dword biSizeImage;long biXPelsPerMeter;long biYPelsPerMeter;dword biClrUsed;dword biClrImportant;'

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

    $_tBMIH = DllStructCreate($_tagBITMAPINFOHEADER)
    DllStructSetData($_tBMIH, 'biSize', DllStructGetSize($_tBMIH))
    DllStructSetData($_tBMIH, 'biWidth', $_iWidth)
    DllStructSetData($_tBMIH, 'biHeight', $_iHeight)
    DllStructSetData($_tBMIH, 'biPlanes', 1)
    DllStructSetData($_tBMIH, 'biBitCount', $_iDepth * $_iChannels)
    DllStructSetData($_tBMIH, 'biCompression', 0)
    DllStructSetData($_tBMIH, 'biSizeImage', $_iWidth * $_iHeight)
    DllStructSetData($_tBMIH, 'biXPelsPerMeter', 0)
    DllStructSetData($_tBMIH, 'biYPelsPerMeter', 0)
    DllStructSetData($_tBMIH, 'biClrUsed', 0)
    DllStructSetData($_tBMIH, 'biClrImportant', 0)

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

    Local $_hBitmap = _WinAPI_CreateDIBSection(0, $_tBMIH, 0, $_pBitmapBits)
    _WinAPI_SetBitmapBits($_hBitmap, $_iWidth * $_iHeight * $_iChannels, $_pData)
    Return $_hBitmap
    EndFunc

    [/autoit]


    Bild gibts hier: https://www.box.com/s/f0gs0ulqbttghzv3c4d2

  • Hab jetzt mein Script nochmal verkürzt, vielleicht kann mir jemand ja helfen.

    Spoiler anzeigen
    [autoit]

    #include "OpenCV.au3"
    #include <GDIPlus.au3>
    #include <WinAPIEx.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    Global $tImage, $hGui, $hGraphics, $hBitmap, $hImage

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

    _OpenCV_Startup()
    $tImage = _OpenCV_LoadImage(@DesktopDir & "\Kamera Test.bmp")
    _OpenCV_Resize2($tImage, 30) ; <<< bei 40% siehts normal aus

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

    $hGui = GUICreate("Test", 800, 800, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_MAXIMIZEBOX))
    GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
    GUISetState()

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

    _GDIPlus_Startup()

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

    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    $hBitmap = _CreateBitmapFromIplImage($tImage)
    $hImage =_GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

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

    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage, 20, 20)

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

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    _Exit()
    EndSwitch
    WEnd

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

    Func _Exit()
    _OpenCV_ReleaseImage($tImage)
    _OpenCV_Shutdown()
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

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

    Func _CreateBitmapFromIplImage($_tIplImage)
    Local $_iWidth = DllStructGetData($_tIplImage, "width")
    Local $_iHeight = DllStructGetData($_tIplImage, "height")
    Local $_iDepth = DllStructGetData($_tIplImage, "depth")
    Local $_iChannels = DllStructGetData($_tIplImage, "nChannels")
    Local $_pData = DllStructGetData($_tIplImage, "imageData")

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

    Local $_hBitmap = _WinAPI_CreateDIB($_iWidth, $_iHeight, $_iDepth * $_iChannels)
    _WinAPI_SetBitmapBits($_hBitmap, $_iWidth * $_iHeight * $_iChannels, $_pData)
    Return $_hBitmap
    EndFunc

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

    Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage, 20, 20)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
    EndFunc ;==>MY_WM_PAINT

    [/autoit]
  • Ich verstehe dein Problem nicht. Du hast doch eine GDI+ Bitmap erstellt, mit der du doch arbeiten kannst.

    Vielleicht kannst du nochmals beschrieben, wo der Schuh klemmt.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Was meinst du mit transformiert?

    Wenn du das Bild in die GUI bekommen willst, dann versuche es mal damit:

    [autoit]


    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, 800, 800)

    [/autoit]

    Ansonsten, wie gesagt, besser beschreiben.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯