Funktionreferenz


_GDIPlus_BitmapUnlockBits

Beschreibung anzeigen in

Gibt einen Teil einer Bitmap frei, die mit _GDIPlus_BitmapLockBits gesperrt wurde

#include <GDIPlus.au3>
_GDIPlus_BitmapUnlockBits ( $hBitmap, $tBitmapData )

Parameter

$hBitmap Handle auf ein Bitmap-Objekt
$tBitmapData $tagGDIPBITMAPDATA-Struktur, die vorher mit _GDIPlus_BitmapLockBits() erzeugt wurde.

Rückgabewert

Erfolg: True
Fehler: False und setzt das @error Flag auf ungleich null, das @extended Flag kann den GPSTATUS-Fehlercode ($GPID_ERR* siehe GDIPlusConstants.au3) enthalten.

Bemerkungen

Wenn keine Notwendigkeit der Sperrung des Bitmap-Bereichs mehr besteht, sollte
durch Aufruf von _GDIPlus_BitmapUnlockBits() der Bereich freigegeben werden.

Verwandte Funktionen

_WinAPI_DeleteObject

Siehe auch

Suche nach GdipBitmapUnlockBits in der MSDN Bibliothek.

Beispiel

Beispiel 1

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; X64 running support
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"

    ;get AutoIt install dir
    Local $sRegPath = "HKLM\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt"

    Local $sFile = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif"
    If Not FileExists($sFile) Then
        MsgBox(($MB_SYSTEMMODAL + $MB_ICONHAND), "", $sFile & " not found!", 30)
        Return False
    EndIf

    _GDIPlus_Startup()
    Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) ;create an image object based on a file
    If @error Then
        _GDIPlus_Shutdown()
        MsgBox(($MB_SYSTEMMODAL + $MB_ICONHAND), "", "An error has occured - unable to load image!", 30)
        Return False
    EndIf

    Local $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) ;get width and height of the image
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $iW, $iH)

    Local $tBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iW, $iH, BitOR($GDIP_ILMWRITE, $GDIP_ILMREAD), $GDIP_PXF32ARGB) ;locks a portion of a bitmap for reading and writing. More infor at http://msdn.microsoft.com/en-us/library/windows/desktop/ms536298(v=vs.85).aspx
    Local $iScan0 = DllStructGetData($tBitmapData, "Scan0") ;get scan0 (pixel data) from locked bitmap
    Local $iSearchPixel = Int(0xFF000080), $iReplaceColor = 0xFF000000 ;color format 0xAARRGGBB
    Local $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0)
    Local $iPixel, $iRowOffset

    For $iY = 0 To $iH - 1
        $iRowOffset = $iY * $iW + 1
        For $iX = 0 To $iW - 1 ;get each pixel in each line and row
            $iPixel = DllStructGetData($tPixel, 1, $iRowOffset + $iX) ;get pixel color
            If $iPixel = $iSearchPixel Then DllStructSetData($tPixel, 1, $iReplaceColor, $iRowOffset + $iX) ;compare and replace pixel color (blue with black color)
        Next
    Next
    _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData) ;unlocks a portion of a bitmap that was locked by _GDIPlus_BitmapLockBits

    ;to save manipulated image just use _GDIPlus_ImageSaveToFile()

    ShellExecute($sFile) ;display original image just to compare with manipulated one

    ;display manipulated image
    Local $hGUI = GUICreate("_GDIPlus_BitmapLockBits Demo", $iW, $iH)
    GUISetState(@SW_SHOW)

    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a Graphics object from a window handle
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH) ;copy manipulated image to graphics handle

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;cleanup resources
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example

Beispiel 2

#include <ScreenCapture.au3>
#include <Color.au3>

_GDIPlus_Startup()

$hBmp = _ScreenCapture_Capture("") ; erstelle Screenshot
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp) ; erstelle ein Bitmap aus Screenshot zur Verwendung mit GDI+
_WinAPI_DeleteObject($hBmp) ; lösche Screenshot aus Speicher

_GreyScale($hBitmap, 50, 50, 300, 200) ; Bereich wird in Graustufen umberechnet

$hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; erstelle Grafikhandle um auf dem Bitmap zu zeichnen
_GDIPlus_GraphicsDrawRect($hGraphics, 50, 50, 300, 200) ; zeichne Umrandung des ergrauten Bereiches
_GDIPlus_GraphicsDispose($hGraphics) ; gibt Grafikhandle wieder frei

_GDIPlus_ImageSaveToFile($hBitmap, @MyDocumentsDir & "\_GDIPlus_BitmapLockBits.jpg") ; speichere fertiges Bild

_GDIPlus_BitmapDispose($hBitmap) ; lösche Bild aus dem Speicher
_GDIPlus_Shutdown()

Func _GreyScale($hBitmap, $iX, $iY, $iW, $iH)
    Local $BitmapData = _GDIPlus_BitmapLockBits($hBitmap, $iX, $iY, $iW, $iH, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32RGB)
    Local $Stride = DllStructGetData($BitmapData, "Stride") ; Stride ist der Offset von einer Reihe zur nächsten
    Local $Width = DllStructGetData($BitmapData, "Width") ; Anzahl der Spalten
    Local $Height = DllStructGetData($BitmapData, "Height") ; Anzahl der Reihen
    Local $Scan0 = DllStructGetData($BitmapData, "Scan0") ; Die Bilddaten im Speicher
    Local $PixelData, $Color, $Luma
    For $row = 0 To $Height - 1 ; Reihe für Reihe
        For $col = 0 To $Width - 1 ; Spalte für Spalte
            ; lese Farbinformation des aktuellen Pixels(Spalte,Reihe) aus
            $PixelData = DllStructCreate("dword", $Scan0 + ($row * $Stride) + ($col * 4))
            $Color = DllStructGetData($PixelData, 1)
            ; berechne Grauwert
            $Luma = _ColorGetRed($Color) * 0.3 + _ColorGetGreen($Color) * 0.59 + _ColorGetBlue($Color) * 0.11
            ; Rot Grün und Blau wert werden jeweils auf den berechneten Grauwert gesetzt
            DllStructSetData($PixelData, 1, BitOR($Luma, BitShift($Luma, -8), BitShift($Luma, -16)))
        Next
    Next
    _GDIPlus_BitmapUnlockBits($hBitmap, $BitmapData)
EndFunc   ;==>_GreyScale