Jump to content

edit screencapture and put it to clipboard problem


Recommended Posts

Hiho folks.

Its time again for me to have a little problem i can't solve:

Following i will try:

- take a screen capture

- modify the capture (add time stamp and some text)

- put the capture to the clipboard

At the moment the script does :

$hBitmap = _ScreenCapture_Capture("", $iX1 + 1, $iY1 + 1, $iX2-1, $iY2-1, False)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
_GDIPlus_GraphicsDrawString ( $hGraphic, "Hello", 10, 3, "Arial", 12)
_GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "\Capture.bmp")
$hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$iResult = _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP )

The saved picture contains the "Hello" string but the SetDataEx command returns with a 0.

And i can't figure out why.

$hBitmap is a handle to a HBITMAP

$hImage is a handle to a bitmap object

$hGraphic is a handle to a graphic object

_GDIPlus_BitmapCreateHBITMAPFromBitmap needs a handle to a bitmap object (=>$hImage) and returns a handle to a HBITMAP (=>$hBitmap2)

_ClipBoard_SetDataEx gets the handle to the HBITMAP object (=>$hBitmap2) and the format parameter $CF_BITMAP

So everthing seems right but SetDataEx won't work.

Has somebody a hint for me?

thx in advance

Sundance

Link to comment
Share on other sites

Try:

_ClipBoard_Open(0)
_ClipBoard_Empty()
$iResult = _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP )
_ClipBoard_Close()

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thx UEZ for the fast reply. I tried and overlooked my code but it won't function. The 0 result of the _CliBoard_SetDataEx was my failure. I mistyped the $iResult variable in the consolewrite with $iresult :-)

Here is a little testscript which also won't do:

#include <Clipboard.au3>
#include <ScreenCapture.au3>

Global $hBitmap, $hBitmap2, $hImage, $iResult
$hBitmap = _ScreenCapture_Capture("", 10, 10, 300, 300, False)
_ClipBoard_Open(0)
_ClipBoard_Empty()
_GDIPlus_Startup()
$hImage  = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
ConsoleWrite("$hImage: " & $hImage & @CRLF)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
ConsoleWrite("$hGraphic: " & $hGraphic & @CRLF)
    _GDIPlus_GraphicsDrawString ( $hGraphic, "Hello", 10, 3, "Arial", 12)
_GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "Capture.bmp")
$hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$iResult = _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP )
ConsoleWrite("$hBitmap2: " & $hBitmap2 & @CRLF & "$iresult: " & $iResult & @CRLF)

_ClipBoard_Close()
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_ShutDown ( )

The saved picture is fine but nothing is in the clipboard...

thx

Sundance

Link to comment
Share on other sites

Try this code:

#include <Constants.au3>
#include <Clipboard.au3>
#include <ScreenCapture.au3>

Global $hBitmap, $hBitmap2, $hImage, $iResult
$hBitmap = _ScreenCapture_Capture("", 10, 10, 300, 300, False)
_ClipBoard_Open(0)
_ClipBoard_Empty()
_GDIPlus_Startup()
$hImage  = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
ConsoleWrite("$hImage: " & $hImage & @CRLF)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
ConsoleWrite("$hGraphic: " & $hGraphic & @CRLF)
    _GDIPlus_GraphicsDrawString ( $hGraphic, "Hello", 10, 3, "Arial", 12)
;~ _GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "Capture.bmp")
$hBitmap2 = _WinAPI_CopyImage(_GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG)
$iResult = _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP )
ConsoleWrite("$hBitmap2: " & $hBitmap2 & @CRLF & "$iresult: " & $iResult & @CRLF)

_ClipBoard_Close()
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_ShutDown ( )

Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0); from _WinAPIEx by Yashied
    Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)
    If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
    Return $Ret[0]
EndFunc   ;==>_WinAPI_CopyImage

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

It works. Many thanks. But why doesn't my script work? It should be....

I tried the whole day to get it running and you need minutes... (shame on me)

thx

Sundance

PS: Ich werd blass. Wie bist du darauf gekommen? Danke Dir!! :idea:

Edited by Sundance
Link to comment
Share on other sites

It works. Many thanks. But why doesn't my script work? It should be....

I tried the whole day to get it running and you need minutes... (shame on me)

thx

Sundance

PS: Ich werd blass. Wie bist du darauf gekommen? Danke Dir!! :idea:

Ich hatte das gleiche Problem mit dem Windows Screenshooter ;)

Gruß,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 4 weeks later...

Try this code:

#include <Constants.au3>
#include <Clipboard.au3>
#include <ScreenCapture.au3>

Global $hBitmap, $hBitmap2, $hImage, $iResult
$hBitmap = _ScreenCapture_Capture("", 10, 10, 300, 300, False)
_ClipBoard_Open(0)
_ClipBoard_Empty()
_GDIPlus_Startup()
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
ConsoleWrite("$hImage: " & $hImage & @CRLF)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
ConsoleWrite("$hGraphic: " & $hGraphic & @CRLF)
_GDIPlus_GraphicsDrawString ( $hGraphic, "Hello", 10, 3, "Arial", 12)
;~ _GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "Capture.bmp")
$hBitmap2 = _WinAPI_CopyImage(_GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG)
$iResult = _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP )
ConsoleWrite("$hBitmap2: " & $hBitmap2 & @CRLF & "$iresult: " & $iResult & @CRLF)

_ClipBoard_Close()
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_ShutDown ( )

Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0); from _WinAPIEx by Yashied
    Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)
    If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
    Return $Ret[0]
EndFunc ;==>_WinAPI_CopyImage

Br,

UEZ

Hello!

I'm using your script to copy a png to clipboard (only way i found to paste images in Excel) but it copies to png file without transparency.

Is it possible to preserve transparency?

Here's your script edited to use an already existing image file (png):

#include <Constants.au3>
#include <Clipboard.au3>
#include <ScreenCapture.au3>

Global $hBitmap, $hBitmap2, $hImage, $iResult
;~ $hBitmap = _ScreenCapture_Capture("", 10, 10, 300, 300, False)
_ClipBoard_Open(0)
_ClipBoard_Empty()
_GDIPlus_Startup()
;~ $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "frame.png")
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
$hBitmap2 = _WinAPI_CopyImage(_GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG)
$iResult = _ClipBoard_SetDataEx($hBitMap2, $CF_BITMAP )
_ClipBoard_Close()
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_ShutDown ( )

Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0); from _WinAPIEx by Yashied
Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)
If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
Return $Ret[0]
EndFunc ;==>_WinAPI_CopyImage
Edited by telmob
Link to comment
Share on other sites

I searched the web for a solution and found this link: http://www.notesoncode.com/articles/2010/08/16/HandlingTransparentImagesOnTheClipboardIsForSomeReasonHard.aspx

I tried to convert a part of it but something is still wrong here!

#include <Constants.au3>
#include <Clipboard.au3>
#include <GDIPlus.au3>

_GDIPlus_Startup()

Global $hBitmap = _GDIPlus_BitmapCreateFromFile(StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUITorus.png"))

$hHBitmap = WinAPI_BitmapCreateDIBFromBitmap($hBitmap)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hHBitmap = ' & $hHBitmap & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

;~ Global $hBitmap2 = _WinAPI_CopyImage($hHBitmap, 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG + $LR_CREATEDIBSECTION) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms648031(v=vs.85).aspx

_ClipBoard_Open(0)
_ClipBoard_Empty()
$iResult = _ClipBoard_SetDataEx($hHBitmap, $CF_DIBV5)
;~ $iResult = _ClipBoard_SetDataEx($hHBitmap, $CF_BITMAP)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iResult = ' & $iResult & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
If $iResult Then MsgBox(0, "Success", "Image copied to clipboard properly!", 10)
_ClipBoard_Close()

_GDIPlus_BitmapDispose($hBitmap)
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_ShutDown ( )
Exit

;~ Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0); from _WinAPIEx by Yashied
;~     Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)
;~     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
;~     Return $Ret[0]
;~ EndFunc   ;==>_WinAPI_CopyImage

Func WinAPI_BitmapCreateDIBFromBitmap($hBitmap)
    Local $tBIHDR, $Ret, $tData, $pBits, $hResult = 0
    $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($Ret[0]) Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $Ret[2], $Ret[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then Return 0
    Local Const $tagBITMAPV5HEADER = 'dword bV5Size;long bV5Width;long bV5Height;ushort bV5Planes;ushort bV5BitCount;dword bV5Compression;dword bV5SizeImage;long bV5XPelsPerMeter;long bV5YPelsPerMeter;dword bV5ClrUsed;dword bV5ClrImportant;dword bV5RedMask;dword bV5GreenMask;dword bV5BlueMask;dword bV5AlphaMask;dword bV5CSType;int bV5Endpoints[3];dword bV5GammaRed;dword bV5GammaGreen;dword bV5GammaBlue;dword bV5Intent;dword bV5ProfileData;dword bV5ProfileSize;dword bV5Reserved;'

    Local Const $tBIV5HDR = DllStructCreate($tagBITMAPV5HEADER)
    DllStructSetData($tBIV5HDR, 'bV5Size', DllStructGetSize($tBIV5HDR))
    DllStructSetData($tBIV5HDR, 'bV5Width', $Ret[2])
    DllStructSetData($tBIV5HDR, 'bV5Height', $Ret[3])
    DllStructSetData($tBIV5HDR, 'bV5Planes', 1)
    DllStructSetData($tBIV5HDR, 'bV5BitCount', 32)
    DllStructSetData($tBIV5HDR, 'bV5Compression', 3) ; $BI_BITFIELDS = 3
    DllStructSetData($tBIV5HDR, 'bV5SizeImage', $Ret[3] * DllStructGetData($tData, 'Stride'))
    DllStructSetData($tBIV5HDR, 'bV5RedMask', 0x00FF0000)
    DllStructSetData($tBIV5HDR, 'bV5GreenMask', 0x0000FF00)
    DllStructSetData($tBIV5HDR, 'bV5BlueMask', 0x000000FF)
    DllStructSetData($tBIV5HDR, 'bV5AlphaMask', 0xFF000000)
    DllStructSetData($tBIV5HDR, 'bV5CSType', 2) ; LCS_WINDOWS_COLOR_SPACE = 2
    DllStructSetData($tBIV5HDR, 'bV5Intent', 4) ; $LCS_GM_IMAGES = 4

    $hResult = _WinAPI_CreateDIBSection(0, $tBIV5HDR, 0, $pBits) ;$DIB_RGB_COLORS = 0

    If (Not @error) And $hResult Then
;~      Local $tPixel
;~      Local $Stride = DllStructGetData($tData, "Stride")
;~      Local $Scan0 = DllStructGetData($tData, "Scan0")
;~      $tBits = DllStructCreate('dword[' & $Ret[2] * $Ret[3] & ']', $pBits)
;~      For $y = 0 To $Ret[3]
;~          For $x = 1 To $Ret[2]
;~              $tPixel = DllStructCreate("int", $Scan0 + ($y * $Stride) + ($x * 4))
;~              $iPixel = DllStructGetData($tPixel, 1)
;~              DllStructSetData($tBits, 1, $iPixel, $x + ($Ret[2] * $y))
;~          Next
;~      Next
        _WinAPI_SetBitmapBits($hResult, $Ret[2] * $Ret[3] * 4, DllStructGetData($tData, 'Scan0'))
    Else
        $hResult = 0
    EndIf
    $tPixel = 0
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    Return $hResult
EndFunc   ;==>_GDIPlus_BitmapCreateDIBFromBitmap

Func _WinAPI_SetBitmapBits($hBitmap, $iSize, $pBits)
    Local $Ret = DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hBitmap, 'dword', $iSize, 'ptr', $pBits)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_SetBitmapBits

Func _WinAPI_CreateDIBSection($hDC, $tBITMAPINFO, $iUsage, ByRef $pBits, $hSection = 0, $iOffset = 0)
    $pBits = 0
    Local $Ret = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', $hDC, 'ptr', DllStructGetPtr($tBITMAPINFO), 'uint', $iUsage, 'ptr*', 0, 'ptr', $hSection, 'dword', $iOffset)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    $pBits = $Ret[4]
    Return $Ret[0]
EndFunc   ;==>_WinAPI_CreateDIBSection

I cannot see the issue why it is not working.

Maybe somebody can help here!

Some small corrections to your code:

#include <Constants.au3>
#include <Clipboard.au3>
#include <ScreenCapture.au3>

Global $hHBitmap, $hBitmap2, $hImage, $iResult
_GDIPlus_Startup()
;~ $hBitmap = _ScreenCapture_Capture("", 10, 10, 300, 300, False)
_ClipBoard_Open(0)
_ClipBoard_Empty()
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "frame.png")
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hBitmap2 = _WinAPI_CopyImage($hHBitmap, 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG)
$iResult = _ClipBoard_SetDataEx($hBitMap2, $CF_BITMAP )
_ClipBoard_Close()
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hHBitmap)
_WinAPI_DeleteObject($hBitmap2)
_GDIPlus_ShutDown ( )
Exit

Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0); from _WinAPIEx by Yashied
Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)
If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
Return $Ret[0]
EndFunc ;==>_WinAPI_CopyImage

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks for your reply UEZ.

I'm going nuts over this....

_ClipPutFile works great except for MS-Excel... If i paste it first in a word document (for example) and then copy/paste it manually into Excel it works, but not via autoit automation. :(

Link to comment
Share on other sites

I'm still working on it and I've a bitmapv5 but it is empty...

#include <Constants.au3>
#include <Clipboard.au3>
#include <GDIPlus.au3>
;~ #include  "WinAPIEx.au3"
_GDIPlus_Startup()

Global $hBitmap = _GDIPlus_BitmapCreateFromFile(StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUITorus.png"))

$hHBitmap = WinAPI_BitmapCreateDIBFromBitmap($hBitmap)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hHBitmap = ' & $hHBitmap & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

_ClipBoard_Open(0)
_ClipBoard_Empty()

;~ Global $hBitmap2 = _WinAPI_CopyImage($hHBitmap, 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms648031(v=vs.85).aspx

$iResult = _ClipBoard_SetDataEx($hHBitmap, $CF_DIBV5)
;~ $iResult = _ClipBoard_SetDataEx($hHBitmap, $CF_BITMAP)
;~ $iResult = _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iResult = ' & $iResult & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
If $iResult Then MsgBox(0, "Success", "Image copied to clipboard properly!", 10)

_ClipBoard_Close()

_GDIPlus_BitmapDispose($hBitmap)
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_Shutdown()
Exit

;~ Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0); from _WinAPIEx by Yashied
;~     Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)
;~     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
;~     Return $Ret[0]
;~ EndFunc   ;==>_WinAPI_CopyImage

Func WinAPI_BitmapCreateDIBFromBitmap($hBitmap)
    Local $aRet, $tData, $pBits, $hResult = 0, $tBIV5HDR, $iBuffLen, $hMem, $pPackedDIBV5, $iStride, $iScan0

    Local Const $tagBITMAPV5HEADER = 'dword bV5Size;long bV5Width;long bV5Height;ushort bV5Planes;ushort bV5BitCount;dword bV5Compression;dword bV5SizeImage;long bV5XPelsPerMeter;long bV5YPelsPerMeter;dword bV5ClrUsed;dword bV5ClrImportant;dword bV5RedMask;dword bV5GreenMask;dword bV5BlueMask;dword bV5AlphaMask;dword bV5CSType;int bV5Endpoints[3];dword bV5GammaRed;dword bV5GammaGreen;dword bV5GammaBlue;dword bV5Intent;dword bV5ProfileData;dword bV5ProfileSize;dword bV5Reserved;'

    $aRet = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($aRet[0]) Then Return 0

    $tBIV5HDR = DllStructCreate($tagBITMAPV5HEADER)

    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $aRet[2], $aRet[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $iStride = DllStructGetData($tData, "Stride")
    $iScan0 = DllStructGetData($tData, "Scan0")

    $iBuffLen = DllStructGetSize($tBIV5HDR) + $aRet[3] * $iStride
    $hMem = _MemGlobalAlloc($iBuffLen, BitOR(0x2000, 0x002, 0x0040)) ; -> $GMEM_DDESHARE = 0x2000, $GMEM_MOVEABLE = 0x0002, $GMEM_ZEROINIT = 0x0040
    $pPackedDIBV5 = _MemGlobalLock($hMem)
    $tBIV5HDR = DllStructCreate($tagBITMAPV5HEADER, $pPackedDIBV5)

    DllStructSetData($tBIV5HDR, 'bV5Size', DllStructGetSize($tBIV5HDR))
    DllStructSetData($tBIV5HDR, 'bV5Width', $aRet[2])
    DllStructSetData($tBIV5HDR, 'bV5Height', $aRet[3])
    DllStructSetData($tBIV5HDR, 'bV5Planes', 1)
    DllStructSetData($tBIV5HDR, 'bV5BitCount', 32)
    DllStructSetData($tBIV5HDR, 'bV5Compression', 3) ; $BI_BITFIELDS = 3
    DllStructSetData($tBIV5HDR, 'bV5SizeImage', $aRet[3] * DllStructGetData($tData, 'Stride'))
    DllStructSetData($tBIV5HDR, 'bV5AlphaMask', 0xFF000000)
    DllStructSetData($tBIV5HDR, 'bV5RedMask', 0x00FF0000)
    DllStructSetData($tBIV5HDR, 'bV5GreenMask', 0x0000FF00)
    DllStructSetData($tBIV5HDR, 'bV5BlueMask', 0x000000FF)
    DllStructSetData($tBIV5HDR, 'bV5CSType', 2) ; LCS_WINDOWS_COLOR_SPACE = 2
    DllStructSetData($tBIV5HDR, 'bV5Intent', 4) ; $LCS_GM_IMAGES = 4

    $hResult = _WinAPI_CreateDIBitmap(0, $tBIV5HDR, 0, $pBits) ;$DIB_RGB_COLORS = 0
    $r = _WinAPI_SetBitmapBits($hResult, $aRet[2] * $aRet[3] * 4, $iScan0)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $r = ' & $r & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    _MemGlobalUnlock($hMem)

    Return $hMem
EndFunc   ;==>WinAPI_BitmapCreateDIBFromBitmap

Func _WinAPI_SetBitmapBits($hBitmap, $iSize, $pBits)
    Local $Ret = DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hBitmap, 'dword', $iSize, 'ptr', $pBits)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_SetBitmapBits

Func _WinAPI_CreateDIBitmap($hDC, $tBITMAPINFO, $iUsage, $pBits = 0)
    Local $pBI = DllStructGetPtr($tBITMAPINFO)
    Local $Init = 0
    If $pBits Then
        $Init = 0x04
    EndIf
    Local $Ret = DllCall('gdi32.dll', 'ptr', 'CreateDIBitmap', 'hwnd', $hDC, 'ptr', $pBI, 'dword', $Init, 'ptr', $pBits, 'ptr', $pBI, 'uint', $iUsage)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_CreateDIBitmap

Func _WinAPI_CreateDIBSection($hDC, $tBITMAPINFO, $iUsage, ByRef $pBits, $hSection = 0, $iOffset = 0)
    $pBits = 0
    Local $Ret = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', $hDC, 'ptr', DllStructGetPtr($tBITMAPINFO), 'uint', $iUsage, 'ptr*', 0, 'ptr', $hSection, 'dword', $iOffset)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    $pBits = $Ret[4]
    Return $Ret[0]
EndFunc   ;==>_WinAPI_CreateDIBSection

Maybe someone has an idea...

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

@Sundance, i made a script using 3 Udf's Jscript, I hope to help you.

Link: http://www.mediafire.com/?u3490z4v4dt1yy0

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

×
×
  • Create New...