[Beispiel] Bild aus Inet auf Gui anzeigen ohne ein TMP-File zu erzeugen

  • angeregt durch [ offen ] Gleiche Werte aus Quelltext auslesen wollte ich natürlich Wissen ob meine Theorie stimmt. Zu allererst ein grosses Danke an UEZ bis auf lächerliche 6 Zeilen Code von mir selbst, ist das komplette Skript aus Skripten von ihm zusammenkopiert).

    Und hier ist das Wunderwerk:

    Spoiler anzeigen
    [autoit]

    ; *** Start added by AutoIt3Wrapper ***
    #include <GUIConstantsEx.au3>
    ; *** End added by AutoIt3Wrapper ***
    #region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_Add_Constants=n
    #endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <GDIPlus.au3>
    #include <Memory.au3>
    #include <INet.au3>
    #include <String.au3>

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

    Local Const $width = 351
    Local Const $height = 470
    Local $hGraphics, $hBackbuffer, $hBitmap, $i, $pi_div_180 = 4 * ATan(1) / 180
    Local $w_h = $width * 0.5, $h_h = $height * 0.5

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

    Local $title = "Shows Pic from Inet without TMP-File"
    Local $sInfo = "Danke UEZ für:"
    Local $sInfo1 = "Load_BMP_From_Mem"
    Local $sInfo2 = "_WinAPI_CreateStreamOnHGlobal"
    Local $sInfo3 = "_GDIPlus_BitmapCreateFromStream"

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

    Opt("GUIOnEventMode", 1)
    $hwnd = GUICreate($title, $width, $height, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
    GUISetState()

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

    _GDIPlus_Startup()
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphics)
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
    $hImage = Load_BMP_From_Mem(LoadPicFromInet("http://1.2.3.11/bmi/www.autoit.de/wcf/images/avatars/avatar-865.png"))
    _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hImage, 0, 0, $width, $height)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $width, $height) ;kopiere Backbuffer in die GUI
    $hBrush = _GDIPlus_BrushCreateSolid(); $Color)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 18, 5)
    $tLayout = _GDIPlus_RectFCreate($width - 190, $height - 130)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sInfo, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGraphics, $sInfo, $hFont, $aInfo[0], $hFormat, $hBrush)
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate($width - 280, $height - 80)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sInfo1, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGraphics, $sInfo1, $hFont, $aInfo[0], $hFormat, $hBrush)
    $tLayout = _GDIPlus_RectFCreate($width - 280, $height - 60)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sInfo2, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGraphics, $sInfo2, $hFont, $aInfo[0], $hFormat, $hBrush)
    $tLayout = _GDIPlus_RectFCreate($width - 280, $height - 40)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sInfo3, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGraphics, $sInfo3, $hFont, $aInfo[0], $hFormat, $hBrush)
    GUIRegisterMsg(0x000F, "WM_PAINT") ;$WM_PAINT = 0x000F

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

    While 1
    WEnd

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

    Func _exit()
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_exit

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

    Func LoadPicFromInet($sUrl)
    Return "0x" & _StringToHex(_INetGetSource($sUrl, True))
    EndFunc ;==>LoadPicFromInet

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

    Func WM_PAINT()
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $width, $height) ;kopiere Backbuffer in die GUI
    Return "GUI_RUNDEFMSG"
    EndFunc

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

    Func Load_BMP_From_Mem($pic)
    ;UEZ postet in http://www.autoit.de/index.php?page…0225#post170225
    Local $memBitmap, $len, $tMem, $hImage, $hData, $pData, $hStream, $hBitmapFromStream
    $memBitmap = Binary($pic)
    $len = BinaryLen($memBitmap)

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

    $hData = _MemGlobalAlloc($len, 0x0002)
    $pData = _MemGlobalLock($hData)
    $tMem = DllStructCreate("byte[" & $len & "]", $pData)
    DllStructSetData($tMem, 1, $memBitmap)
    _MemGlobalUnlock($hData)

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

    $hStream = _WinAPI_CreateStreamOnHGlobal($pData)
    $hBitmapFromStream = _GDIPlus_BitmapCreateFromStream($hStream)
    $tMem = ""
    Return $hBitmapFromStream
    EndFunc ;==>Load_BMP_From_Mem

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

    Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $fDeleteOnRelease = True)
    ;UEZ postet in http://www.autoit.de/index.php?page…0225#post170225
    Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "hwnd", $hGlobal, "int", $fDeleteOnRelease, "ptr*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[3]
    EndFunc ;==>_WinAPI_CreateStreamOnHGlobal

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

    Func _GDIPlus_BitmapCreateFromStream($pStream)
    ;UEZ postet in http://www.autoit.de/index.php?page…0225#post170225
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
    EndFunc ;==>_GDIPlus_BitmapCreateFromStream

    [/autoit]

    Ps.: ich selbst werde bei solchen Anlässen weiter den koventionellen Weg

    [autoit]

    InetGet
    GuiCtrlCreatePic

    [/autoit]

    gehen, wollte nur aufzeigen dass es funktioniert,

    Edit: Skript ausgetauscht um dem GDI+ Meister gebührend zu danken für seine Funktionen, speziell

    • Load_BMP_From_Mem
    • _WinAPI_CreateStreamOnHGlobal
    • _GDIPlus_BitmapCreateFromStream

    Bei Verwendung dieser Funktionen bestehe ich auch auf der Nennung von UEZ als Urheber,

    mfg autoBert

    4 Mal editiert, zuletzt von autoBert (29. August 2010 um 04:28)