UDF > GDIPlus > Bitmap >


_GDIPlus_BitmapCreateFromScan0

Crée un objet Bitmap à partir d'un tableau d'octets, de la taille et du format

#include <GDIPlus.au3>
_GDIPlus_BitmapCreateFromScan0 ( $iWidth, $iHeight [, $iPixelFormat = $GDIP_PXF32ARGB [, $iStride = 0 [, $pScan0 = 0]]] )

Paramètres

$iWidth La largeur du bitmap, en pixels.
$iHeight La hauteur du bitmap, en pixels.
$iPixelFormat [optionnel] Spécifie le format des données de pixels.
    $GDIP_PXF01INDEXED = 1 bit par pixel, indexés
    $GDIP_PXF04INDEXED = 4 bits par pixel, indexés
    $GDIP_PXF08INDEXED = 8 bits par pixel, indexés
    $GDIP_PXF16GRAYSCALE = 16 bits par pixel, niveaux de gris
    $GDIP_PXF16RGB555 = 16 bits par pixel; 5 bits pour chaque composante RVB
    $GDIP_PXF16RGB565 = 16 bits par pixel; 5 bits pour le rouge, 6 bits pour le vert et 5 bits bleu
    $GDIP_PXF16ARGB1555 = 16 bits par pixel; 1 bit pour l'alpha et 5 bits pour chaque composante RVB
    $GDIP_PXF24RGB = 24 bits par pixel; 8 bits pour chaque composante RGB
    $GDIP_PXF32RGB = 32 bits par pixel; 8 bits pour chaque composante RGB. Aucune composante alpha.
    $GDIP_PXF32ARGB = 32 bits par pixel; 8 bits pour chaque composante RVB et alpha
    $GDIP_PXF32PARGB = 32 bits par pixel; 8 bits pour chaque composante RVB pré-multipliée en fonction de la composante alpha
$iStride [optionnel] Entier qui spécifie l'offset entre le début d'une ligne de balayage et la suivante.
$pScan0 [optionnel] Pointeur vers un tableau d'octets qui contient les données de pixels.

Valeur de retour

Succès: Retourne le handle d'un nouvel objet Bitmap.
Échec: Retourne 0 et définit @error <> 0, @extended contient le code erreur GPSTATUS ($GPID_ERR*).

Remarque

Lorsque vous en avez terminé avec l'objet, appelez _GDIPlus_BitmapDispose() pour libérer les ressources de l'objet.

En relation

_GDIPlus_ImageDispose

Voir aussi

Consultez GdipCreateBitmapFromScan0 dans la Librairie MSDN.

Exemples

Exemple 1

#include <GDIPlus.au3>

Example()

Func Example()
    _GDIPlus_Startup()
    Local Const $iW = 460, $iH = 100
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ; Crée un bitmap vide
    Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; Obtient le contexte graphique de l'image bitmap
    _GDIPlus_GraphicsSetSmoothingMode($hBmpCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
    _GDIPlus_GraphicsClear($hBmpCtxt, 0xFFFFFFFF) ; Efface le bitmap avec la couleur blanche
    _GDIPlus_GraphicsDrawString($hBmpCtxt, "AutoIt rulez!", 0, 0, "Comic Sans MS", 52) ; Dessine un peu de texte dans le bitmap
    Local $sFile = @TempDir & "\Test.jpg"
    _GDIPlus_ImageSaveToFile($hBitmap, $sFile) ; Sauvegarde le bitmap sur le disque
    ; Nettoie les ressources GDI+
    _GDIPlus_GraphicsDispose($hBmpCtxt)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    ShellExecute($sFile) ; Ouvre le bitmap avec l'application par défaut
EndFunc   ;==>Example

Exemple 2

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

Example()

Func Example()
    _GDIPlus_Startup()
    Local Const $iW = 120, $iH = 80

    Local $hGui = GUICreate("", $iW, $iH)
    GUISetState()
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)

    Local $tPixel = DllStructCreate("uint[" & $iW * $iH & "];")
    Local $iOffset
    For $y = 0 To $iH - 1
        $iOffset = $y * $iW
        For $x = 0 To $iW - 1
            Local $aColor[3] = [Random(0, 255, 1), Random(0, 255, 1), Random(0, 255, 1)]
            DllStructSetData($tPixel, 1, BitOR(0xFF000000, _ColorSetRGB($aColor)), $iOffset + $x + 1)
        Next
    Next

    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH, $GDIP_PXF32ARGB, $iW, $tPixel)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)

    Local $iMsg
    Do
       $iMsg = GUIGetMsg() 
       If $iMsg = $GUI_EVENT_RESTORE Then
            _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0) ; Redessine le bitmap
        EndIf
    Until $iMsg = $GUI_EVENT_CLOSE

    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example