Funktionreferenz


_WinAPI_CreateDIBSection

Beschreibung anzeigen in

Erzeugt eine DIB in die Anwendungen direkt schreiben können.

#include <WinAPIGdi.au3>
_WinAPI_CreateDIBSection ( $hDC, $tBITMAPINFO, $iUsage, ByRef $pBits [, $hSection = 0 [, $iOffset = 0]] )

Parameter

$hDC Das Handle eines Gerätekontextes. Wenn der Wert des $iUsage Parameters $DIB_PAL_COLORS ist, so verwendet diese Funktion die logische Palette des Gerätekontextes um die DIB Farben zu initialisieren.
$tBITMAPINFO Die $tagBITMAPINFO Struktur welche diverse Attribute der DIB angibt, einschließlich der Dimensionen und Farben der Bitmap.
$iUsage Der Typ welcher für die Farben (entweder logisch Palettenindizes oder tatsächliche Farben) verwendet werden soll. Dieser Parameter muss einer der folgenden Werte annehmen:
    $DIB_PAL_COLORS
    $DIB_RGB_COLORS
$pBits Gibt einen Pointer zu dem Ort der DIB Bit Werte zurück.
$hSection [optional] Das Handle eines file-mapping Objektes welches die Funktion verwendet um die DIB zu erzeugen.
$iOffset [optional] Der Versatz zum Anfang des file-mapping Objektes, referenziert durch $hSection, wo der Speicher für die Bitmapbitwerte beginnen soll. Dieser Wert wird ignoriert sofern $hSection 0 ist (Standard).

Rückgabewert

Erfolg: Das Handle zum neu erzeugten DIB und $pBits zeigt auf die Bitmapbitwerte.
Man kann die Struktur mittels dem $pBits Pointer erzeugen um das Füllen voranzutreiben.
Zum Beispiel, DllStructCreate('dword[256]', $pBits).
Fehler: 0, $pBits wird auf 0 gesetzt.

Bemerkungen

Wenn die Arbeit mit der Bitmap abgeschlossen ist, so sollte man sie mit der _WinAPI_DeleteObject() Funktion zerstören.

Verwandte Funktionen

_WinAPI_DeleteObject

Siehe auch

Suche nach CreateDIBSection in der MSDN Bibliothek.

Beispiel

#include <APIGdiConstants.au3>
#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIHObj.au3>

; Create 32 bits-per-pixel device-independent bitmap (DIB) that use a mask
Local $tBIV5HDR = DllStructCreate($tagBITMAPV5HEADER)

DllStructSetData($tBIV5HDR, 'bV5Size', DllStructGetSize($tBIV5HDR))
DllStructSetData($tBIV5HDR, 'bV5Width', 256)
DllStructSetData($tBIV5HDR, 'bV5Height', 256)
DllStructSetData($tBIV5HDR, 'bV5Planes', 1)
DllStructSetData($tBIV5HDR, 'bV5BitCount', 32)
DllStructSetData($tBIV5HDR, 'biCompression', $BI_BITFIELDS)
DllStructSetData($tBIV5HDR, 'bV5SizeImage', 0)
DllStructSetData($tBIV5HDR, 'bV5XPelsPerMeter', 0)
DllStructSetData($tBIV5HDR, 'bV5YPelsPerMeter', 0)
DllStructSetData($tBIV5HDR, 'bV5ClrUsed', 0)
DllStructSetData($tBIV5HDR, 'bV5ClrImportant', 0)
DllStructSetData($tBIV5HDR, 'bV5RedMask', 0x00FF0000)
DllStructSetData($tBIV5HDR, 'bV5GreenMask', 0x0000FF00)
DllStructSetData($tBIV5HDR, 'bV5BlueMask', 0x000000FF)
DllStructSetData($tBIV5HDR, 'bV5AlphaMask', 0xFF000000)
DllStructSetData($tBIV5HDR, 'bV5CSType', 0)
DllStructSetData($tBIV5HDR, 'bV5Endpoints', 0, 1)
DllStructSetData($tBIV5HDR, 'bV5Endpoints', 0, 2)
DllStructSetData($tBIV5HDR, 'bV5Endpoints', 0, 3)
DllStructSetData($tBIV5HDR, 'bV5GammaRed', 0)
DllStructSetData($tBIV5HDR, 'bV5GammaGreen', 0)
DllStructSetData($tBIV5HDR, 'bV5GammaBlue', 0)
DllStructSetData($tBIV5HDR, 'bV5Intent', 0)
DllStructSetData($tBIV5HDR, 'bV5ProfileData', 0)
DllStructSetData($tBIV5HDR, 'bV5ProfileSize', 0)
DllStructSetData($tBIV5HDR, 'bV5Reserved', 0)

Local $pBits
Local $hBitmap = _WinAPI_CreateDIBSection(0, $tBIV5HDR, $DIB_RGB_COLORS, $pBits)

; Fill bitmap green with variable alpha channel
Local $tBits = DllStructCreate('dword[65536]', $pBits)
For $y = 0 To 255
    For $x = 1 To 256
        DllStructSetData($tBits, 1, BitOR(0x00FF00, BitShift($y, -24)), $x + (256 * $y))
    Next
Next

; Create GUI
Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 256, 256)
Local $idPic = GUICtrlCreatePic('', 0, 0, 256, 256)
Local $hPic = GUICtrlGetHandle($idPic)

; Set bitmap to control
_SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
Local $hObj = _SendMessage($hPic, $STM_GETIMAGE)
If $hObj <> $hBitmap Then
    _WinAPI_DeleteObject($hBitmap)
EndIf

; Set background color to green and show GUI
GUISetBkColor(0x0000FF)
GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE