Jump to content

Calculated BMP to GUI without saving to file first


Go to solution Solved by Nine,

Recommended Posts

Is there a way to convert the $BMP created by BMP.au3 onto a GUI without saving it to file first?

 

;Based on an example by RazerM:

#include <BMP3.au3>
#include <GDIPlus.au3>
$BMP=_BMPCreate(150,150)

For $x=0 to 50
    For $y=0 to 50
        _PixelWrite($BMP,$x,$y,'0000FF') ;blue
    Next
Next
For $x=100 to 150
    For $y=0 to 50
        _PixelWrite($BMP,$x,$y,'ff0000') ;red
    Next
Next
For $x=100 to 150
    For $y=100 to 150
        _PixelWrite($BMP,$x,$y,'00ff00') ;green
    Next
Next
For $x=0 to 50
    For $y=100 to 150
        _PixelWrite($BMP,$x,$y,'000000') ;black
    Next
Next
For $x=50 to 100
    For $y=50 to 100
        _PixelWrite($BMP,$x,$y,'999999') ;grey
    Next
Next


;_BMPWrite($BMP,@ScriptDir & "\MyBMP.bmp");Closes the BMP to a file

Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($Bmp)
_WinAPI_DeleteObject($Bmp)

Local $hGUI = GUICreate("Example", 800, 800)
GUISetState()

Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)


Do
    $msg = GUIGetMsg()
Until $msg = -3;$GUI_EVENT_CLOSE

 

Link to comment
Share on other sites

  • Solution

Just use GDI+.  I do not know this UDF, but it seems to create a .bmp file from scratch.

#include <GDIPlus.au3>
#include <GUIConstants.au3>

_GDIPlus_Startup()
Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(200, 200)
Local $tBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, 200, 200, BitOR($GDIP_ILMWRITE, $GDIP_ILMREAD), $GDIP_PXF32ARGB)
Local $iScan0 = DllStructGetData($tBitmapData, "Scan0")
Local $tPixel = DllStructCreate("int[" & 200 * 200 & "];", $iScan0)

PixelWrite($tPixel, 200, 0, 0, 99, 99, 0xFFFF0000)
PixelWrite($tPixel, 200, 100, 0, 199, 99, 0xFF00FF00)
PixelWrite($tPixel, 200, 0, 100, 99, 199, 0xFF0000FF)
PixelWrite($tPixel, 200, 100, 100, 199, 199, 0xFF00FFFF)

_GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData)
Local $hGUI = GUICreate("Example", 200, 200)
GUISetState()

Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()

Func PixelWrite(ByRef $tStruc, $iWidth, $iXs, $iYs, $iXe, $iYe, $nColor)
  For $j = $iYs To $iYe
    $iRowOffset = $j * $iWidth + 1
    For $i = $iXs To $iXe
      DllStructSetData($tStruc, 1, $nColor, $iRowOffset + $i)
    Next
  Next
EndFunc

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...