# Function Reference

# _GDIPlus_BitmapCreateFromScan0

Creates a Bitmap object based on an array of bytes along with size and format information

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

## Parameters

$iWidth | The bitmap width, in pixels.
$iHeight | The bitmap height, in pixels.
$iPixelFormat | [optional] Specifies the format of the pixel data. $GDIP_PXF01INDEXED = 1 bit per pixel, indexed $GDIP_PXF04INDEXED = 4 bits per pixel, indexed $GDIP_PXF08INDEXED = 8 bits per pixel, indexed $GDIP_PXF16GRAYSCALE = 16 bits per pixel, grayscale $GDIP_PXF16RGB555 = 16 bits per pixel; 5 bits for each RGB component $GDIP_PXF16RGB565 = 16 bits per pixel; 5 bits for red, 6 bits for green and 5 bits blue $GDIP_PXF16ARGB1555 = 16 bits per pixel; 1 bit for alpha and 5 bits for each RGB component $GDIP_PXF24RGB = 24 bits per pixel; 8 bits for each RGB component $GDIP_PXF32RGB = 32 bits per pixel; 8 bits for each RGB component. No alpha component. $GDIP_PXF32ARGB = 32 bits per pixel; 8 bits for each RGB and alpha component $GDIP_PXF32PARGB = 32 bits per pixel; 8 bits for each RGB and alpha component, pre-multiplied
$iStride | [optional] Integer that specifies the byte offset between the beginning of one scan line and the next.
$pScan0 | [optional] Pointer to an array of bytes that contains the pixel data.

## Return Value

Success: | a handle to a new Bitmap object.
Failure: | 0 and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GDIP_ERR* see GPIPlusConstants.au3).

## Remarks

After you are done with the object, call _GDIPlus_BitmapDispose() to release the object resources.

## Related

_GDIPlus_ImageDispose

## See Also

Search GdipCreateBitmapFromScan0 in MSDN Library.

## Example

### Example 1

    #include <GDIPlus.au3>

    Example()

    Func Example()
        _GDIPlus_Startup()
        Local Const $iW = 460, $iH = 100
        Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ;create an empty bitmap
        Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the graphics context of the bitmap
        _GDIPlus_GraphicsSetSmoothingMode($hBmpCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
        _GDIPlus_GraphicsClear($hBmpCtxt, 0xFFFFFFFF) ;clear bitmap with color white
        _GDIPlus_GraphicsDrawString($hBmpCtxt, "AutoIt rulez!", 0, 0, "Comic Sans MS", 52) ;draw some text to the bitmap
        Local $sFile = @TempDir & "\Test.jpg"
        _GDIPlus_ImageSaveToFile($hBitmap, $sFile) ;save bitmap to disk
        ;cleanup GDI+ resources
        _GDIPlus_GraphicsDispose($hBmpCtxt)
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_Shutdown()
        ShellExecute($sFile) ;open bitmap with default app
    EndFunc   ;==>Example

### Example 2

    #include <GDIPlus.au3>
    #include <GUIConstantsEx.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
                DllStructSetData($tPixel, 1, BitOR(0xFF000000, BitShift(Random(0, 255, 1), -16), BitShift(Random(0, 255, 1), -8), Random(0, 255, 1)), $iOffset + $x + 1)
            Next
        Next

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

        While 1
            Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                    ExitLoop

                Case $GUI_EVENT_RESTORE
                    ; to redraw the Bitmap
                    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
            EndSwitch
        WEnd

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