Yashied

_GDIPlus_BitmapCreateBitmapWithAlpha()

12 posts in this topic

#1 ·  Posted (edited)

This small function allows you to add an alpha channel (mask) to the specified GDI+ bitmap (see screenshots). Source bitmap and mask may be of any color depth. The output bitmap is always 32 bits-per-pixel with alpha channel. Optionally, the alpha channel may be generated from any channel of the specified mask (1 - Red, 2 - Green, 3 - Blue, or 0 - Alpha). The example below is written for Autoit 3.3.12.0.

 

post_img_094.pngpost_img_095.pngpost_img_096.png

#Include <GDIPlus.au3>

If StringRegExpReplace(@AutoItVersion, '(?<!\d)(\d)(?!\d)', '0\1') < '03.03.12.00' Then
    MsgBox(16, 'Error', 'Require AutoIt 3.3.12.0 or later.')
EndIf

_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Image.png')
$hAlpha = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Alpha.png')
$hResult = _GDIPlus_BitmapCreateBitmapWithAlpha($hBitmap, $hAlpha, 1)
_GDIPlus_ImageSaveToFile($hResult, @ScriptDir & '\Image+Alpha.png')
_GDIPlus_BitmapDispose($hResult)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_BitmapDispose($hAlpha)
_GDIPlus_Shutdown()

Func _GDIPlus_BitmapCreateBitmapWithAlpha($hBitmap, $hAlpha, $iChannel = 0)

    Local $hGraphics, $hBmp[2], $bProc, $tProc, $pProc, $Size1, $Size2, $Lenght, $Result
    Local $tData[2] = [$GDIP_ILMWRITE, $GDIP_ILMREAD]

    $Size1 = DllCall($__g_hGDIPDll, 'uint', 'GdipGetImageDimension', 'handle', $hBitmap, 'float*', 0, 'float*', 0)
    If (@Error) Or ($Size1[0]) Then
        Return 0
    EndIf
    $Size2 = DllCall($__g_hGDIPDll, 'uint', 'GdipGetImageDimension', 'handle', $hAlpha, 'float*', 0, 'float*', 0)
    If (@Error) Or ($Size2[0]) Then
        Return 0
    EndIf
    $hBmp[0] = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $Size1[2], $Size1[3], $GDIP_PXF32ARGB)
    If ($Size1[2] = $Size2[2]) And ($Size1[3] = $Size2[3]) Then
        $hBmp[1] = $hAlpha
    Else
        $hBmp[1] = _GDIPlus_BitmapCreateFromScan0($Size1[2], $Size1[3], $GDIP_PXF32ARGB)
        $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBmp[1])
        _GDIPlus_GraphicsClear($hGraphics, 0)
        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hAlpha, 0, 0, $Size1[2], $Size1[3])
        _GDIPlus_GraphicsDispose($hGraphics)
    EndIf
    If ($iChannel < 0) Or ($iChannel > 3) Then
        $iChannel = 0
    EndIf
    For $i = 0 To 1
        $tData[$i] = _GDIPlus_BitmapLockBits($hBmp[$i], 0, 0, $Size1[2], $Size1[3], $tData[$i], $GDIP_PXF32ARGB)
    Next
    If @AutoItX64 Then
        $bProc = Binary('0x48894C240848895424104C894424184C894C24205541574831C0505050504883EC2848837C24600074054831C0EB0748C7C0010000004821C00F858100000048837C24680074054831C0EB0748C7C0010000004821C07555837C24700074054831C0EB0748C7C0010000004821C0752A4C637C24784D21FF7C0D4C637C24784983FF037F02EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000EB034831C04821C0740B4831C04863C0E9950000004C8B7C24604983C7034C897C24284C8B7C246848634424784929C74983C7034C897C243048C7442438000000004C637C247049FFCF4C3B7C24387C4A488B6C24284C0FB67D00488B6C2430480FB645004C0FAFF84C89F848C7C1FF000000489948F7F94989C74C89F850488B6C24305888450048834424280448834424300448FF44243871A748C7C0010000004863C0EB034831C04883C448415F5DC3')
    Else
        $bProc = Binary('0x555331C0505050837C241800740431C0EB05B80100000021C07568837C241C00740431C0EB05B80100000021C07545837C242000740431C0EB05B80100000021C075228B5C242421DB7C0B8B5C242483FB037F02EB07B801000000EB0231C021C07502EB07B801000000EB0231C021C07502EB07B801000000EB0231C021C07502EB07B801000000EB0231C021C0740431C0EB6B8B5C241883C303891C248B5C241C2B5C242483C303895C2404C7442408000000008B5C24204B3B5C24087C368B2C240FB65D008B6C24040FB645000FAFD889D8B9FF00000099F7F989C3538B6C240458884500830424048344240404FF44240871BFB801000000EB0231C083C40C5B5DC21000')
    EndIf
    $Length = BinaryLen($bProc)
    $pProc = DllCall('kernel32.dll', 'ptr', 'VirtualAlloc', 'ptr', 0, 'ulong_ptr', $Length, 'dword', 0x1000, 'dword', 0x0040)
    $tProc = DllStructCreate('byte[' & $Length & ']', $pProc[0])
    DllStructSetData($tProc, 1, $bProc)
    $Result = DllCallAddress('uint', $pProc[0], 'ptr', $tData[0].Scan0, 'ptr', $tData[1].Scan0, 'uint', $Size1[2] * $Size1[3], 'uint', $iChannel)
    If Not $Result[0] Then
        ; Nothing
    EndIf
    DllCall('kernel32.dll', 'int', 'VirtualFree', 'ptr', $pProc[0], 'ulong_ptr', 0, 'dword', 0x4000)
    For $i = 0 To 1
        _GDIPlus_BitmapUnlockBits($hBmp[$i], $tData[$i])
    Next
    If $hBmp[1] <> $hAlpha Then
        _GDIPlus_BitmapDispose($hBmp[1])
    EndIf
    Return $hBmp[0]
EndFunc   ;==>_GDIPlus_BitmapCreateBitmapWithAlpha

Function + Example

Previous downloads: 47

GDIPlus_BitmapCreateBitmapWithAlpha.zip

Edited by Yashied
1 person likes this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If @AutoItVersion <> '3.3.12.0' Then

?? small typo ??

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Can you post the ASM code please (if possible with comments)?

Thanks.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

....

;~If @AutoItVersion <> '3.3.12.0' Then
;~  MsgBox(16, 'Error', 'Require AutoIt 3.3.12.0 or later.')
;~EndIf

....

 

this should do: (from >here)

; use 3 digits for each portion of the version without dots
; (Leading zeros are not needed)
; 3.3.12.0 -> 003.003.012.000 -> 3003012000

If _AutoItVersion() < 3003012000 Then
    MsgBox(16, 'Error', 'Require AutoIt 3.3.12.0 or later.')
EndIf

Func _AutoItVersion()
    Local $aAutoItV = StringSplit(@AutoItVersion, ".", 2)
    Return StringFormat("%03i%03i%03i%03i", $aAutoItV[0], $aAutoItV[1], $aAutoItV[2], $aAutoItV[3])
EndFunc   ;==>_AutoItVersion

p.s.

sorry for the little offtopic hijacking

1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Excellent code. I too would like to "study" the ASM code. -_0


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

this should do: (from >here)

; use 3 digits for each portion of the version without dots
; (Leading zeros are not needed)
; 3.3.12.0 -> 003.003.012.000 -> 3003012000

If _AutoItVersion() < 3003012000 Then
    MsgBox(16, 'Error', 'Require AutoIt 3.3.12.0 or later.')
EndIf

Func _AutoItVersion()
    Local $aAutoItV = StringSplit(@AutoItVersion, ".", 2)
    Return StringFormat("%03i%03i%03i%03i", $aAutoItV[0], $aAutoItV[1], $aAutoItV[2], $aAutoItV[3])
EndFunc   ;==>_AutoItVersion

p.s.

sorry for the little offtopic hijacking

 

I was just wondering how to solve the "task", which @Yashied want to use.

 

EDIT:

My example.

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

I was just wondering how to solve the "task", which @Yashied want to use.

 

... I've already thought >few days ago :) ...


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I too would like to "study" the ASM code.

I didn't write ASM code, I wrote and compiled DLL in other language and then retrieved a binary code of appropriate function. In AutoIt this function looks like this, but in AutoIt it takes a lot of time.

Func _AddAlpha($pBits1, $pBits2, $iWidth, $iHeght, $iChannel)
    If (Not $pBits1) Or (Not $pBits2) Or ($iChannel < 0) Or ($iChannel > 3) Then Return 0
    Local $iOffset = 3 - $iChannel
    For $i = 0 To $iWidth * $iHeght * 4 - 4 Step 4
        Local $tData1 = DllStructCreate('byte', $pBits1 + $i + 3)
        Local $tData2 = DllStructCreate('byte', $pBits2 + $i + $iOffset)
        DllStructSetData($tData1, 1, DllStructGetData($tData1, 1) * DllStructGetData($tData2, 1) / 255)
    Next
    Return 1
EndFunc

Retrieving binary code:

#Include <WinAPIEx.au3>

$File = FileOpenDialog('Select File', @ScriptDir, 'Libraries (*.dll)|All Files (*.*)', 1 + 2)
If Not $File Then
    Exit
EndIf
$hModule = _WinAPI_LoadLibrary($File)
If Not $hModule Then
    MsgBox(0x00040010, 'Error', 'Unable to load ' & StringRegExpReplace($File, '^.*\\', '') & '.')
    Exit
EndIf
Do
    $pFirst = _WinAPI_GetProcAddress($hModule, 'First')
    If @Error Then
        MsgBox(0x00040010, 'Error', '"First()" procedure not found.')
        ExitLoop
    EndIf
    $pLast = _WinAPI_GetProcAddress($hModule, 'Last')
    If @Error Then
        MsgBox(0x00040010, 'Error', '"Last()" procedure not found.')
        ExitLoop
    EndIf
    $tData = DllStructCreate('byte[' & Number($pLast - $pFirst) & ']', $pFirst)
    If @Error Then
        MsgBox(0x00040010, 'Error', 'Invalid addresses.')
        ExitLoop
    EndIf
    $Code = String(DllStructGetData($tData, 1))
    ConsoleWrite($Code & @CR)
    ClipPut($Code)
Until 1
_WinAPI_FreeLibrary($hModule)

Here Alpha.dll (x86) for example.

Edited by Yashied

Share this post


Link to post
Share on other sites

Ah OK, thanks.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I've decided to experiment and wrote a version of this function by using threads (up to 4). Yes, it reduced the time to perform external function, but unfortunately most of the time consuming _GDIPlus... function. Nevertheless, if anyone is interested here is a function.

 

#Include <GDIPlus.au3>

If StringRegExpReplace(@AutoItVersion, '(?<!\d)(\d)(?!\d)', '0\1') < '03.03.12.00' Then
    MsgBox(16, 'Error', 'Require AutoIt 3.3.12.0 or later.')
EndIf

_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Image.png')
$hAlpha = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Alpha.png')
$hResult = _GDIPlus_BitmapCreateBitmapWithAlpha($hBitmap, $hAlpha, 1)
_GDIPlus_ImageSaveToFile($hResult, @ScriptDir & '\Image+Alpha.png')
_GDIPlus_BitmapDispose($hResult)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_BitmapDispose($hAlpha)
_GDIPlus_Shutdown()

Func _GDIPlus_BitmapCreateBitmapWithAlpha($hBitmap, $hAlpha, $iChannel = 0)

    Local $hGraphics, $hBmp[2], $hThread, $iThread, $tParams, $bProc, $tProc, $pProc, $aSize1, $aSize2, $aLength, $iLength, $iOffset, $aResult
    Local $tData[2] = [$GDIP_ILMWRITE, $GDIP_ILMREAD]

    $aSize1 = DllCall($__g_hGDIPDll, 'uint', 'GdipGetImageDimension', 'handle', $hBitmap, 'float*', 0, 'float*', 0)
    If (@Error) Or ($aSize1[0]) Then
        Return 0
    EndIf
    $aSize2 = DllCall($__g_hGDIPDll, 'uint', 'GdipGetImageDimension', 'handle', $hAlpha, 'float*', 0, 'float*', 0)
    If (@Error) Or ($aSize2[0]) Then
        Return 0
    EndIf
    $hBmp[0] = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $aSize1[2], $aSize1[3], $GDIP_PXF32ARGB)
    If ($aSize1[2] = $aSize2[2]) And ($aSize1[3] = $aSize2[3]) Then
        $hBmp[1] = $hAlpha
    Else
        $hBmp[1] = _GDIPlus_BitmapCreateFromScan0($aSize1[2], $aSize1[3], $GDIP_PXF32ARGB)
        $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBmp[1])
        _GDIPlus_GraphicsClear($hGraphics, 0)
        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hAlpha, 0, 0, $aSize1[2], $aSize1[3])
        _GDIPlus_GraphicsDispose($hGraphics)
    EndIf
    If ($iChannel < 0) Or ($iChannel > 3) Then
        $iChannel = 0
    EndIf
    For $i = 0 To 1
        $tData[$i] = _GDIPlus_BitmapLockBits($hBmp[$i], 0, 0, $aSize1[2], $aSize1[3], $tData[$i], $GDIP_PXF32ARGB)
    Next
    If @AutoItX64 Then
        $bProc = Binary('0x48894C24085541574831C0505050504883EC28488B6C246048837D000074054831C0EB0748C7C0010000004821C00F8591000000488B6C246048837D080074054831C0EB0748C7C0010000004821C07561488B6C2460837D100074054831C0EB0748C7C0010000004821C07532488B6C24604C637D144D21FF7C11488B6C24604C637D144983FF037F02EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000EB034831C04821C0740B4831C04863C0E9A5000000488B6C24604C8B7D004983C7034C897C2428488B6C24604C8B7D08488B6C2460486345144929C74983C7034C897C243048C744243800000000488B6C24604C637D1049FFCF4C3B7C24387C4A488B6C24284C0FB67D00488B6C2430480FB645004C0FAFF84C89F848C7C1FF000000489948F7F94989C74C89F850488B6C24305888450048834424280448834424300448FF44243871A348C7C0010000004863C0EB034831C04883C448415F5DC3')
    Else
        $bProc = Binary('0x555331C05050508B6C2418837D0000740431C0EB05B80100000021C075748B6C2418837D0400740431C0EB05B80100000021C0754E8B6C2418837D0800740431C0EB05B80100000021C075288B6C24188B5D0C21DB7C0E8B6C24188B5D0C83FB037F02EB07B801000000EB0231C021C07502EB07B801000000EB0231C021C07502EB07B801000000EB0231C021C07502EB07B801000000EB0231C021C0740431C0EB778B6C24188B5D0083C303891C248B6C24188B5D048B6C24182B5D0C83C303895C2404C7442408000000008B6C24188B5D084B3B5C24087C368B2C240FB65D008B6C24040FB645000FAFD889D8B9FF00000099F7F989C3538B6C240458884500830424048344240404FF44240871BCB801000000EB0231C083C40C5B5DC20400')
    EndIf
    $iLength = BinaryLen($bProc)
    $pProc = DllCall('kernel32.dll', 'ptr', 'VirtualAlloc', 'ptr', 0, 'ulong_ptr', $iLength, 'dword', 0x1000, 'dword', 0x0040)
    $tProc = DllStructCreate('byte[' & $iLength & ']', $pProc[0])
    DllStructSetData($tProc, 1, $bProc)
    $iLength = $aSize1[2] * $aSize1[3]
    Select
        Case $iLength > 2 ^ 24
            $iThread = 4
        Case $iLength > 2 ^ 20
            $iThread = 2
        Case Else
            $iThread = 1
    EndSelect
    Dim $aLength[$iThread]
    Dim $tParams[$iThread]
    Dim $hThread[$iThread]
    If $iThread = 1 Then
        $aLength[0] = $iLength
    Else
        $aLength[0] = Floor($iLength / $iThread)
        $aLength[$iThread - 1] = $iLength - $aLength[0] * ($iThread - 1)
        For $i = 1 To $iThread - 2
            $aLength[$i] = $aLength[0]
        Next
    EndIf
    $iOffset = 0
    For $i = 0 To $iThread - 1
        $tParams[$i] = DllStructCreate('ptr;ptr;uint;uint')
        DllStructSetData($tParams[$i], 1, $tData[0].Scan0 + $iOffset)
        DllStructSetData($tParams[$i], 2, $tData[1].Scan0 + $iOffset)
        DllStructSetData($tParams[$i], 3, $aLength[$i])
        DllStructSetData($tParams[$i], 4, $iChannel)
        $iOffset+= 4 * $aLength[$i]
        $aResult = DllCall('kernel32.dll', 'handle', 'CreateThread', 'ptr', 0, 'dword_ptr', 0, 'ptr', $pProc[0], 'struct*', $tParams[$i], 'dword', 0, 'ptr', 0)
        If (Not @Error) And ($aResult[0]) Then
            $hThread[$i] = $aResult[0]
        Else
            $hThread[$i] = 0
        EndIf
    Next
    While 1
        $iLength = 0
        For $i = 0 To $iThread - 1
            If $hThread[$i] Then
                $aResult = DllCall('kernel32.dll', 'bool', 'GetExitCodeThread', 'handle', $hThread[$i], 'dword*', 0)
                If (@Error) Or (Not $aResult[0]) Or ($aResult[2] <> 259) Then
                    DllCall('kernel32.dll', 'bool', 'CloseHandle', 'handle', $hThread[$i])
                    $hThread[$i] = 0
                Else
                    $iLength += 1
                EndIf
            EndIf
        Next
        If Not $iLength Then
            ExitLoop
        EndIf
    WEnd
    $aResult = DllCall('kernel32.dll', 'int', 'VirtualFree', 'ptr', $pProc[0], 'ulong_ptr', 0, 'dword', 0x4000)
    If (@Error) Or (Not $aResult[0]) Then
        ; Nothing
    EndIf
    For $i = 0 To 1
        _GDIPlus_BitmapUnlockBits($hBmp[$i], $tData[$i])
    Next
    If $hBmp[1] <> $hAlpha Then
        _GDIPlus_BitmapDispose($hBmp[1])
    EndIf
    Return $hBmp[0]
EndFunc   ;==>_GDIPlus_BitmapCreateBitmapWithAlpha
Edited by Yashied

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I added an experimental ASM version:

 

#Include <GDIPlus.au3>

If StringRegExpReplace(@AutoItVersion, '(?<!\d)(\d)(?!\d)', '0\1') < '03.03.12.00' Then
    MsgBox(16, 'Error', 'Require AutoIt 3.3.12.0 or later.')
EndIf

If FileExists(@ScriptDir & '\Image+AlphaASM.png') Then FileDelete(@ScriptDir & '\Image+AlphaASM.png')
_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Image.png')
$hAlpha = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Alpha.png')
_GDIPlus_BitmapCreateBitmapWithAlphaASM($hBitmap, $hAlpha)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & '\Image+AlphaASM.png')
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_BitmapDispose($hAlpha)
_GDIPlus_Shutdown()
ShellExecute(@ScriptDir & '\Image+AlphaASM.png')

Func _GDIPlus_BitmapCreateBitmapWithAlphaASM($hBitmap, $hBitmap_AlphaMask) ;coded by UEZ build 2015-02-26
    Local $fTimer_All = TimerInit()
    Local Const $iWidth = _GDIPlus_ImageGetWidth($hBitmap), $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
    If _GDIPlus_ImageGetWidth($hBitmap_AlphaMask) <> $iWidth Or _GDIPlus_ImageGetHeight($hBitmap) <> $iHeight Then Return SetError(1, 0, 0)
    Local Const $tBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iWidth, $iHeight, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)
    Local Const $pScan = $tBitmapData.Scan0
    Local Const $iStride = $tBitmapData.Stride
    Local Const $tPixelData = DllStructCreate("dword[" & (Abs($iStride * $iHeight)) & "]", $pScan)

    Local Const $tBitmapAlphaMaskData = _GDIPlus_BitmapLockBits($hBitmap_AlphaMask, 0, 0, $iWidth, $iHeight, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    Local Const $pScanAlpha = $tBitmapAlphaMaskData.Scan0
    Local Const $iStrideAlpha = $tBitmapAlphaMaskData.Stride
    Local Const $tPixelAlphaMaskData = DllStructCreate("dword[" & (Abs($iStrideAlpha * $iHeight)) & "]", $pScanAlpha)

    Local $fTimer_ASM = TimerInit()
    Local $tCodeBuffer = DllStructCreate("byte ASM[46]")
    $tCodeBuffer.ASM = "0x8B7424048B4C24088B7C240C8B0625FFFFFF008B1F81E30000FF00C1E30809D8890683C60483C70483E90177DFC3"
    DllCall("user32.dll", "ptr", "CallWindowProcW", "ptr", DllStructGetPtr($tCodeBuffer), _
                          "ptr", DllStructGetPtr($tPixelData), _
                          "int", $iWidth * $iHeight , _
                          "ptr", DllStructGetPtr($tPixelAlphaMaskData), "int",0)
    ConsoleWrite("ASM: " & TimerDiff($fTimer_ASM) & " ms." & @CRLF)

    _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData)
    _GDIPlus_BitmapUnlockBits($hBitmap_AlphaMask, $tBitmapData)
    ConsoleWrite("Overall: " & TimerDiff($fTimer_All) & " ms." & @CRLF)
    Return 1
EndFunc

#cs ASM
      .data:0x00000000    8b742404        mov    esi,DWORD PTR [esp+0x4]  ;start address of the bitmap
      .data:0x00000004    8b4c2408        mov    ecx,DWORD PTR [esp+0x8]  ;number of pixel -> $iWidth * $iHeight
      .data:0x00000008    8b7c240c        mov    edi,DWORD PTR [esp+0xc]  ;start address of the alpha mask bitmap
      .data:0x0000000c
      .data:0x0000000c        loc_0000000c:
┏▶  .data:0x0000000c    8b06            mov    eax,DWORD PTR [esi]      ;get the pixel from the bitmap
┃     .data:0x0000000e    25ffffff00      and    eax,0xffffff             ;remove alpha channel
┃     .data:0x00000013    8b1f            mov    ebx,DWORD PTR [edi]      ;get the pixel from alpha mask bitmap
┃     .data:0x00000015    81e30000ff00    and    ebx,0xff0000             ;get red value only because r=g=b (greyscale). This will be our alpha channel
┃     .data:0x0000001b    c1e308          shl    ebx,0x8                  ;shift the value to the alpha channel place AArrggbb
┃     .data:0x0000001e    09d8            or     eax,ebx                  ;add the alpha channel value to the bitmap pixel
┃     .data:0x00000020    8906            mov    DWORD PTR [esi],eax      ;write the pixel to the bitmap -> should be a greyscaled color value
┃     .data:0x00000022    83c604          add    esi,0x4                  ;address next pixel: 3 Byte = 1 dword = 1 Pixel
┃     .data:0x00000025    83c704          add    edi,0x4                  ;address next pixel: 3 Byte = 1 dword = 1 Pixel
┃     .data:0x00000028    83e901          sub    ecx,0x1                  ;counter (next pixel)
┗     .data:0x0000002b    77df            ja     loc_0000000c             ;jump as long as counter is not zero
      .data:0x0000002d    c3              ret
 

My results for the images on op:

ASM: 0.196242006627889 ms.

Overall: 8.97499269224327 ms.

 

 

Maybe a MMX/SSE and/or 64-bit version(s) will follow... ;)

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
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

  • Similar Content

    • c.haslam
      By c.haslam
      sometimes!
      Running the script below and entering a for All seems to work every time Running it and choosing 1 for One returns a gibberish string However with the same functions, I have seen it succeed when 1 is chosen, i.e. show the value for the test property ID 0x0103 as OLYMPUS DIGITAL CAMERA I have also seen GetOne() succeed when a diagnostic MsgBox() is added,  and when I include my debugging functions, so the problem appears to be a memory location being overwritten, probably in a DLLStruct.. call.
      I know that value OLYMPUS DIGITAL CAMERA is correct from Irfanview and from running GetAll().
      All but one of the _GDIPlus functions were written by ChrisL. I have modified those that returned a DLLStruct object such that they now return an array.
      Both getting one and getting  all involve calling _GDIPlus_ImageGetPropertyItemValue() which I wrote, so perhaps the problem partly lies with ChrisL's functions as modified.
      Suggestions?
      #include <GDIPlus.au3> #include <Array.au3> Opt('MustDeclareVars',1) ; #VARIABLES# =================================================================================================================== Global $GDIP_STATUS = 0 Global $GDIP_ERROR = 0 ; =============================================================================================================================== ; Property Item structure Global Const $tagGDIPPROPERTYITEM = _ "uint id;" & _ ; ID of this property "uint length;" & _ ; Length of the property value, in bytes "ushort type;" & _ ; Type of the value, as one of TAG_TYPE_XXX constants "ptr value;" ; property value ; Image property types constants ; Ref: https://www.media.mit.edu/pia/Research/deepview/exif.html Global Const $GDIP_PROPERTYTAGTYPEUBYTE = 1 Global Const $GDIP_PROPERTYTAGTYPEASCII = 2 Global Const $GDIP_PROPERTYTAGTYPEUSHORT = 3 Global Const $GDIP_PROPERTYTAGTYPEULONG = 4 Global Const $GDIP_PROPERTYTAGTYPEURATIONAL = 5 Global Const $GDIP_PROPERTYTAGTYPESBYTE = 6 Global Const $GDIP_PROPERTYTAGTYPEUNDEFINED = 7 Global Const $GDIP_PROPERTYTAGTYPESSHORT = 8 Global Const $GDIP_PROPERTYTAGTYPESLONG = 9 Global Const $GDIP_PROPERTYTAGTYPESRATIONAL = 10 Global Const $GDIP_PROPERTYTAGTYPESFLOAT = 11 Global Const $GDIP_PROPERTYTAGTYPEDFLOAT = 12 main() Func main() _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile('H:\b\PA160005 - Copy.JPG') Local $sAns = InputBox('','Enter 1 or a') If $sAns=1 Then GetOne($hImage) ElseIf $sAns='a' Then GetAll($hImage) EndIf _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() EndFunc Func GetOne($hImage) Local $vecPrim = _GDIPlus_ImageGetPropertyItem($hImage,0x010e) Local $vecUser[3] $vecUser[0] = '0x'&StringRight(Hex($vecPrim[0]),4) $vecUser[1] = $vecPrim[2] Local $vecVals = _GDIPlus_ImageGetPropertyItemValue($vecPrim[1],$vecPrim[2],$vecPrim[3]) $vecUser[2] = $vecVals[0] _ArrayDisplay($vecUser) EndFunc Func GetAll($hImage) Local $ar1 = _GDIPlus_ImageGetAllPropertyItems($hImage) Local $ar[UBound($ar1,1)][3] For $i = 1 To $ar1[0][0] $ar[$i][0] = '0x'&StringRight(Hex($ar1[$i][0]),4) $ar[$i][1] =$ar1[$i][2] $ar[$i][2] = (_GDIPlus_ImageGetPropertyItemValue($ar1[$i][1],$ar1[$i][2],$ar1[$i][3]))[0] Next _ArrayDisplay($ar) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetAllPropertyItems ; Description ...: Gets all the property items (metadata) stored in an Image object ; Syntax.........: _GDIPlus_ImageGetAllPropertyItems($hImage) ; Parameters ....: $hImage - Pointer to an Image object ; Return values .: Success - Array containing the image property items: ; |[0][0] - Number of property items ; |[1][0] - Property item 1 identifier (see remarks) ; |[1][1] - Property item 1 value length, in bytes ; |[1][2] - Property item 1 value type ; |[1][1] - Property item 1 value pointer ; |. ; |. ; |[n][0] - Property item n identifier ; |[n][1] - Property item n value length, in bytes ; |[n][2] - Property item n value type ; |[n][1] - Property item n value pointer ; Possible property value types are: ; |1 - The value pointer points to an array of bytes ; |2 - The value pointer points to a null-terminated ASCII string ; |3 - The value pointer points to unsigned short ; |4 - The value pointer points to an unsigned long ; |5 - The value pointer points to an array of unsigned two longs (numerator, denominator) ; |7 - The value pointer points to an array of bytes of any type, or is unterminated string\ ; |8 - The value pointer points to signed short ; |9 - The value pointer points to a signed long ; |10 - The value pointer points to an array of signed two longs (numerator, denominator) ; |11 - The value pointer points to a float ; |12 - The value pointer points to a double ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; |$GDIP_ERROR: ; | 1 - The _GDIPlus_ImageGetPropertySize function failed, $GDIP_STATUS contains the error code ; | 2 - The image contains no property items metadata ; | 3 - The _GDIPlus_ImageGetAllPropertyItems function failed, $GDIP_STATUS contains the error code ; Author.........: Authenticity ; Modified.......: c.haslam ; Remarks .......: The property item tag identifiers are declared in GDIPConstants.au3, those that start with $GDIP_PROPERTYTAG ; +The value size is given in bytes, divide this by the size of the data (4 for integers, 2 for shorts, etc..) ; Related .......: _GDIPlus_ImageGetPropertySize, _GDIPlus_ImageGetPropertyItemValue, _GDIPlus_ImageGetAllPropertyItems ; Link ..........; @@MsdnLink@@ GdipGetAllPropertyItems ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetAllPropertyItems($hImage) Local $iI, $iCount, $tBuffer, $pBuffer, $iBuffer, $tPropertyItem, $aSize, $aPropertyItems[1][1], $aResult $aSize = _GDIPlus_ImageGetPropertySize($hImage) If @error Then Return SetError(@error, @extended, -1) If $GDIP_STATUS Then $GDIP_ERROR = 1 Return -1 ElseIf $aSize[1] = 0 Then $GDIP_ERROR = 2 Return -1 EndIf $iBuffer = $aSize[0] $tBuffer = DllStructCreate("byte[" & $iBuffer & "]") $pBuffer = DllStructGetPtr($tBuffer) $iCount = $aSize[1] $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetAllPropertyItems", "hwnd", $hImage, "uint", $iBuffer, "uint", $iCount, "ptr", $pBuffer) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then $GDIP_ERROR = 3 Return -1 EndIf ReDim $aPropertyItems[$iCount + 1][4] $aPropertyItems[0][0] = $iCount For $iI = 1 To $iCount $tPropertyItem = DllStructCreate($tagGDIPPROPERTYITEM, $pBuffer) $aPropertyItems[$iI][0] = DllStructGetData($tPropertyItem, "id") $aPropertyItems[$iI][1] = DllStructGetData($tPropertyItem, "length") $aPropertyItems[$iI][2] = DllStructGetData($tPropertyItem, "type") $aPropertyItems[$iI][3] = DllStructGetData($tPropertyItem, "value") $pBuffer += DllStructGetSize($tPropertyItem) Next Return $aPropertyItems EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GDIPlus_ImageGetPropertyItemValue ; Description ...: Get property item values from fields in $tagGDIPPROPERTYITEM data ; Syntax ........: _GDIPlus_ImageGetPropertyItemValue($iLength, $iType, $pValue) ; Parameters ....: $iLength Length of the property value, in bytes ; |$iType Type of the value (a $GDIP_PROPERTYTAGTYPE* value - see GDIPConstants.au3) ; |$pValue Pointer to value ; Return values .: Success - An array ; | [0] value 1 ; | [1] value 2 (only for properties that have numerator and denominator) ; Failure - -1 ; Author ........: c.haslam ; Modified ......: ; Remarks........: If type is 7 ($GDIP_PROPERTYTAGTYPEUNDEFINED) value returned is an unsigned long. ; Depending on ID and originator of the image, value may actually be an unterminated string ; Related .......: _GDIPlus_ImageGetPropertyItem,_GDIPlus_ImageGetAllPropertyItems ; Link ..........: http://www.cipa.jp/std/documents/e/DC-008-Translation-2016-E.pdf, ; https://www.media.mit.edu/pia/Research/deepview/exif.html ; Example .......: No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyItemValue($iLength, $iType, $pValue) Switch $iType Case $GDIP_PROPERTYTAGTYPEURATIONAL,$GDIP_PROPERTYTAGTYPESRATIONAL Local $aRet[2] Case Else Local $aRet[1] EndSwitch Switch $iType Case $GDIP_PROPERTYTAGTYPEUBYTE,$GDIP_PROPERTYTAGTYPESBYTE Local $tvalue = DllStructCreate('byte val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEASCII Local $tvalue = DllStructCreate('char val['&$iLength&']',$pValue) If @error Then MsgBox(0,@ScriptLineNumber,'@error='&@error) $aRet[0] = DllStructGetData($tvalue,'val') If @error Then MsgBox(0,@ScriptLineNumber,'@error='&@error) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEUSHORT Local $tvalue = DllStructCreate('ushort val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEULONG Local $tvalue = DllStructCreate('ulong val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEURATIONAL Local $tvalue = DllStructCreate('ulong val1;ulong val2',$pValue) $aRet[0] = $tvalue.val1 $aRet[1] = $tvalue.val2 Case $GDIP_PROPERTYTAGTYPESBYTE Local $tvalue = DllStructCreate('byte val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEUNDEFINED ; undefined, per specification, but may be a long but is sometimes a string Local $tvalue = DllStructCreate('ulong val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPESSHORT Local $tvalue = DllStructCreate('short val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEULONG Local $tvalue = DllStructCreate('ulong val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPESRATIONAL Local $tvalue = DllStructCreate('long val1;long val2',$pValue) $aRet[0] = $tvalue.val1 $aRet[1] = $tvalue.val2 Case $GDIP_PROPERTYTAGTYPESFLOAT Local $tvalue = DllStructCreate('float val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEDFLOAT Local $tvalue = DllStructCreate('double val',$pValue) $aRet[0] = $tvalue.val EndSwitch $tvalue = 0 Return $aRet EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertyItem ; Description ...: Gets a specified property item (piece of metadata) from an Image object ; Syntax.........: _GDIPlus_ImageGetPropertyItem($hImage, $iPropID) ; Parameters ....: $hImage - Pointer to an Image object ; $iPropID - Identifier of the property item to be retrieved ; Return values .: Success - Array ; | [0] Property ID ; | [1] Property length ; | [2] Property type ; | [3] pointer to Property value ; Possible values of type are: ; |1 - The value pointer points to an array of bytes ; |2 - The value pointer points to a null-terminated ASCII string ; |3 - The value pointer points to unsigned short ; |4 - The value pointer points to an unsigned long ; |5 - The value pointer points to an array of unsigned two longs (numerator, denominator) ; |7 - The value pointer points to an array of bytes of any type, or is unterminated string\ ; |8 - The value pointer points to signed short ; |9 - The value pointer points to a signed long ; |10 - The value pointer points to an array of signed two longs (numerator, denominator) ; |11 - The value pointer points to a float ; |12 - The value pointer points to a double ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non-zero value specifying the error code ; |$GDIP_ERROR: ; | 1 - The _GDIPlus_ImageGetPropertyItemSize function failed, $GDIP_STATUS contains the error code ; | 2 - The specified property identifier does not exist in the image ; | 3 - The _GDIPlus_ImageGetPropertyItem function failed, $GDIP_STATUS contains the error code ; Author.........: Authenticity ; Modified.......: c.haslam ; Remarks .......: None ; Related .......: _GDIPlus_ImageGetPropertyIdList, _GDIPlus_ImageGetPropertyItemSize, _GDIPlus_ImageGetPropertyItemValue, ; $tagGDIPPROPERTYITEM ; Link ..........; @@MsdnLink@@ GdipGetPropertyItem http://www.cipa.jp/std/documents/e/DC-008-Translation-2016-E.pdf, ; https://www.media.mit.edu/pia/Research/deepview/exif.html ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyItem($hImage, $iPropID) Local $iBuffer, $tBuffer, $pBuffer, $tPropertyItem, $aResult $iBuffer = _GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) If @error Then Return SetError(@error, @extended, -1) If $GDIP_STATUS Then $GDIP_ERROR = 1 Return -1 ElseIf $iBuffer = 0 Then $GDIP_ERROR = 2 Return -1 EndIf $tBuffer = DllStructCreate("byte[" & $iBuffer & "]") $pBuffer = DllStructGetPtr($tBuffer) $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertyItem", "hwnd", $hImage, "uint", $iPropID, "uint", $iBuffer, "ptr", $pBuffer) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then $GDIP_ERROR = 3 Return -1 EndIf Local $tPropertyItem = DllStructCreate($tagGDIPPROPERTYITEM, $pBuffer) Local $aRet = [$tPropertyItem.id, $tPropertyItem.length,$tPropertyItem.type, $tPropertyItem.value] Return $aRet EndFunc ;==>_GDIPlus_ImageGetPropertyItem ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertySize ; Description ...: Gets the total size, in bytes, and the number of all the property items stored in an Image object ; Syntax.........: _GDIPlus_ImageGetPropertySize($hImage) ; Parameters ....: $hImage - Pointer to an Image object ; Return values .: Success - Array containing the total size and the number of property items: ; |[0] - Total size, in bytes, of the property items ; |[1] - Number of the property items ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Author.........: Authenticity ; Remarks .......: None ; Related .......: _GDIPlus_ImageGetPropertyIdList, _GDIPlus_ImageGetPropertyItem ; Link ..........; @@MsdnLink@@ GdipGetPropertyItemSize ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertySize($hImage) Local $aSize[2], $aResult $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertySize", "hwnd", $hImage, "uint*", 0, "uint*", 0) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then Return -1 $aSize[0] = $aResult[2] $aSize[1] = $aResult[3] Return $aSize EndFunc ;==>_GDIPlus_ImageGetPropertySize ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertyItemSize ; Description ...: Gets the size, in bytes, of a specified property item of an Image object ; Syntax.........: _GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) ; Parameters ....: $hImage - Pointer to an Image object ; $iPropID - Identifier of the property item to be retrieved ; Return values .: Success - $tagGDIPPROPERTYITEM structure containing the property size, type and value pointer ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Author.........: Authenticity ; Remarks .......: None ; Related .......: _GDIPlus_ImageGetPropertyIdList, _GDIPlus_ImageGetPropertyItem ; Link ..........; @@MsdnLink@@ GdipGetPropertyItemSize ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertyItemSize", "hwnd", $hImage, "uint", $iPropID, _ "uint*", 0) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then Return -1 Return $aResult[3] EndFunc ;==>_GDIPlus_ImageGetPropertyItemSize  
    • c.haslam
      By c.haslam
      The following code is one of my many attempts to get the value of a string property from an image. It doesn't work. I know that IMAGEDESCRIPTION has a string value.
      In one of my many attempts, I did get the string OLYMPUS .., which I know is correct from IrfanView, but I can't get it again.
      How should I get this string?
       
      #include <GDIPlus.au3> Opt('MustDeclareVars',1) ; Property Item structure Global Const $tagGDIPPROPERTYITEM = _ "uint id;" & _ ; ID of this property "uint length;" & _ ; Length of the property value, in bytes "ushort type;" & _ ; Type of the value, as one of TAG_TYPE_XXX constants "ptr value;" ; property value Global Const $GDIP_PROPERTYTAGIMAGEDESCRIPTION = 0x010E ; #VARIABLES# =================================================================================================================== Global $ghGDIPMatrix = 0 Global $GDIP_STATUS = 0 Global $GDIP_ERROR = 0 Local $Dsk_ghImage _GDIPlus_Startup() $Dsk_ghImage = _GDIPlus_ImageLoadFromFile('H:\b\PA160005 - Copy.JPG') Local $propListVec = _GDIPlus_ImageGetPropertyIdList($Dsk_ghImage) Local $qProps = $propListVec[0] For $i = 1 To $qProps $propListVec[$i] = Hex($propListVec[$i]) While StringLeft($propListVec[$i],1)='0' $propListVec[$i] = StringMid($propListVec[$i],2) WEnd ConsoleWrite($propListVec[$i]&@CRLF) Next Local $tProp = _GDIPlus_ImageGetPropertyItem($Dsk_ghImage,$GDIP_PROPERTYTAGIMAGEDESCRIPTION) Local $len = $tProp.length Local $s = 'char str['&$len&']' Local $ptr = $tProp.value Local $tStr = DllStructCreate($s,$ptr) MsgBox(0,'@error',@error) Local $strval = DllStructGetData($tStr,'str') MsgBox(0,'','@error '&@error&' strval '&$strval) ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertyIdList ; Description ...: Gets a list of the property identifiers used in the metadata of an Image object ; Syntax.........: _GDIPlus_ImageGetPropertyIdList($hImage) ; Parameters ....: $hImage - Pointer to an Image object ; Return values .: Success - Array of property identifiers: ; |[0] - Number of property identifiers ; |[1] - Property identifier 1 ; |[2] - Property identifier 2 ; |[n] - Property identifier n ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; |$GDIP_ERROR: ; | 1 - The _GDIPlus_ImageGetPropertyCount function failed, $GDIP_STATUS contains the error code ; | 2 - The image does not contain any property items ; | 3 - The _GDIPlus_ImageGetPropertyIdList function failed, $GDIP_STATUS contains the error code ; Author.........: Authenticity ; Remarks .......: The property item identifiers are declared in GDIPConstants.au3, those that start with $GDIP_PROPERTYTAGN* ; Related .......: _GDIPlus_ImageGetAllPropertyItems, _GDIPlus_ImageGetPropertyCount, _GDIPlus_ImageGetPropertyItem ; Link ..........; @@MsdnLink@@ GdipGetPropertyIdList ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyIdList($hImage) Local $iI, $iCount, $tProperties, $pProperties, $aProperties[1], $aResult $iCount = _GDIPlus_ImageGetPropertyCount($hImage) If @error Then Return SetError(@error, @extended, -1) If $GDIP_STATUS Then $GDIP_ERROR = 1 Return -1 ElseIf $iCount = 0 Then $GDIP_ERROR = 2 Return -1 EndIf $tProperties = DllStructCreate("uint[" & $iCount & "]") $pProperties = DllStructGetPtr($tProperties) $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertyIdList", "hwnd", $hImage, "int", $iCount, "ptr", $pProperties) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then $GDIP_ERROR = 3 Return -1 EndIf ReDim $aProperties[$iCount + 1] $aProperties[0] = $iCount For $iI = 1 To $iCount $aProperties[$iI] = DllStructGetData($tProperties, 1, $iI) Next Return $aProperties EndFunc ;==>_GDIPlus_ImageGetPropertyIdList ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertyItem ; Description ...: Gets a specified property item (piece of metadata) from an Image object ; Syntax.........: _GDIPlus_ImageGetPropertyItem($hImage, $iPropID) ; Parameters ....: $hImage - Pointer to an Image object ; $iPropID - Identifier of the property item to be retrieved ; Return values .: Success - $tagGDIPPROPERTYITEM structure containing the property size, type and value pointer ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; |$GDIP_ERROR: ; | 1 - The _GDIPlus_ImageGetPropertyItemSize function failed, $GDIP_STATUS contains the error code ; | 2 - The specified property identifier does not exist in the image ; | 3 - The _GDIPlus_ImageGetPropertyItem function failed, $GDIP_STATUS contains the error code ; Author.........: Authenticity ; Remarks .......: None ; Related .......: _GDIPlus_ImageGetPropertyIdList, _GDIPlus_ImageGetPropertyItemSize, $tagGDIPPROPERTYITEM ; Link ..........; @@MsdnLink@@ GdipGetPropertyItem ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyItem($hImage, $iPropID) Local $iBuffer, $tBuffer, $pBuffer, $tPropertyItem, $aResult $iBuffer = _GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) If @error Then Return SetError(@error, @extended, -1) If $GDIP_STATUS Then $GDIP_ERROR = 1 Return -1 ElseIf $iBuffer = 0 Then $GDIP_ERROR = 2 Return -1 EndIf $tBuffer = DllStructCreate("byte[" & $iBuffer & "]") $pBuffer = DllStructGetPtr($tBuffer) $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertyItem", "hwnd", $hImage, "uint", $iPropID, "uint", $iBuffer, "ptr", $pBuffer) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then $GDIP_ERROR = 3 Return -1 EndIf $tPropertyItem = DllStructCreate($tagGDIPPROPERTYITEM, $pBuffer) Return $tPropertyItem EndFunc ;==>_GDIPlus_ImageGetPropertyItem ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertyCount ; Description ...: Gets the number of properties (pieces of metadata) stored in an Image object ; Syntax.........: _GDIPlus_ImageGetPropertyCount($hImage) ; Parameters ....: $hImage - Pointer to an Image object ; Return values .: Success - Number of property items store in the Image object ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Author.........: Authenticity ; Remarks .......: None ; Related .......: _GDIPlus_ImageGetAllPropertyItems, _GDIPlus_ImageGetPropertyIdList ; Link ..........; @@MsdnLink@@ GdipGetPropertyCount ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyCount($hImage) Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertyCount", "hwnd", $hImage, "uint*", 0) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then Return -1 Return $aResult[2] EndFunc ;==>_GDIPlus_ImageGetPropertyCount ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertyItemSize ; Description ...: Gets the size, in bytes, of a specified property item of an Image object ; Syntax.........: _GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) ; Parameters ....: $hImage - Pointer to an Image object ; $iPropID - Identifier of the property item to be retrieved ; Return values .: Success - $tagGDIPPROPERTYITEM structure containing the property size, type and value pointer ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Author.........: Authenticity ; Remarks .......: None ; Related .......: _GDIPlus_ImageGetPropertyIdList, _GDIPlus_ImageGetPropertyItem ; Link ..........; @@MsdnLink@@ GdipGetPropertyItemSize ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertyItemSize", "hwnd", $hImage, "uint", $iPropID, "uint*", 0) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then Return -1 Return $aResult[3] EndFunc ;==>_GDIPlus_ImageGetPropertyItemSize  
    • c.haslam
      By c.haslam
      I have found that:
      there are 276 functions in Authenticity's GDIP.au3 (written for 3.3.6.1) that are not in 3.3.14.2's GDIPlus.au3.  there are many constants in his GDIPConstants.au3 that are not in 3.3.14.2's GDIPlus.au3, but there are some that are. So:
      GDIP extras.au3 contains functions that are not in GDIPlus.au3. They have been extracted from GDIP.au3 The revised GDIPConstants.au3 has constants that are duplicates of those in GDIPlus.au3 commented out. They are attached.
      I have done limited testing on 3.3.14.2 with GDIP extras.au3 and the revised GDIPConstants.au3 included.
      I have undertaken this effort in thanks for the help with GDI+ that I have received on this form, especially from UEZ.
      Authenticity's thread is here. For those who do not 7zip, I am attaching his GDIP as a zip file. It contains many examples.
      GDIP33142.zip
      GDIPAuthenticity.zip
    • c.haslam
      By c.haslam
      UEZ has kindly provided me with code that rotates an image per a line: see here
      Because I want to trim a photograph after rotation, I need to crop the photo. I wrote code which calls _GDIPlus_GraphicsSetClipRect() to do this, but it places spurious stuff in the corners: see 2.jpg attached.
      I want only the trimmed photo to show.
      The original jpeg is also attached.
      The arguments to _GDIPlus_GraphicsSetClipRect() come from solving 2 simultaneous equations: if a and b are the width and height of the original photo, find x and y, the width and height of the rotated and cropped rectangle;
      a = x cos(ang) + y sin(ang)
      b = x sin(ang) + y cos(ang)
      My solution is:
      x = (b * sin(ang) - a*cos(ang)) / (sin(ang)^2 - (cos(ang)^2)
      y = (b * cos(ang) - a * sin(ang)) / (cos(ang)^2 - sin(ang)^2)
      To try to get a handle on the problem, I have temporarily added in several lines in Case $btn. In 2.jpg, you can see that the rectangle bounding the area to be retained is in the wrong place.
      The code is:
      #include <ButtonConstants.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars',1) Global Const $MK_SHIFT = 0x4 Global Const $MK_CONTROL = 0x8 Global Const $fPi = ACos(-1), $fPi2 = $fPi / 2, $fRad = 180 / $fPi GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") GUIRegisterMsg($WM_PAINT,'WM_PAINT') Global $gX0=10,$gX1=580,$gY0,$gY1,$gForm1,$glblPic,$iLW,$iLH,$iW,$iH Global $ghCanvas,$ghImage,$ghPen,$gGraphicPic,$ghBitmap,$ghMatrix,$ghImageClone,$ghGfxClone Global Const $kDegToRads = 3.14159/180 main() Func main() $gForm1 = GUICreate("Form1", 623, 601, 192, 114) $iLW = 589 $iLH = 500 $glblPic = GUICtrlCreateLabel("", 8, 8, $iLW, $iLH) Local $btn = GUICtrlCreateButton("Rotate", 472, 560, 65, 25) GUISetState(@SW_SHOW) Local $oldY0,$oldY1,$fAngle _GDIPlus_Startup() $ghPen = _GDIPlus_PenCreate(0xFF999999,2) $ghImage = _GDIPlus_ImageLoadFromFile('H:\b\pergola.jpg') Local $h = GUICtrlGetHandle($glblPic) $gGraphicPic = _GDIPlus_GraphicsCreateFromHWND($h) $gY0 = 400 $gY1 = 400 $iW = _GDIPlus_ImageGetWidth($ghImage) $iH = _GDIPlus_ImageGetHeight($ghImage) $ghBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) $ghCanvas = _GDIPlus_ImageGetGraphicsContext($ghBitmap) $ghMatrix = _GDIPlus_MatrixCreate() ; Loop until the user exits. While True If $gY0<>$oldY0 Or $gY1<>$oldY1 Then Paint() $oldY0 = $gY0 $oldY1 = $gY1 Else Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btn $ghImageClone=_GDIPlus_BitmapCreateFromScan0($iW, $iH) $ghGfxClone=_GDIPlus_ImageGetGraphicsContext($ghImageClone) _GDIPlus_MatrixTranslate($ghMatrix, $iW/2, $iH/2) $gY1 = 300 ; temp Local $ang = -Angle($gY1-$gY0, $gX1-$gX0) _GDIPlus_MatrixRotate($ghMatrix, $ang) ;~ _GDIPlus_MatrixRotate($ghMatrix, -Angle($gY1-$gY0, $gX1-$gX0)) _GDIPlus_MatrixTranslate($ghMatrix, -$iW/2, -$iH/2) _GDIPlus_GraphicsSetTransform($ghGfxClone, $ghMatrix) _GDIPlus_GraphicsDrawImageRect($ghGfxClone,$ghImage,0,0,$iW,$iH) Local $angRads = $ang*$kDegToRads Local $sinAng = Sin($angRads) Local $cosAng = Cos($angRads) Local $wid = ($iLH*$sinAng-$iLW*$cosAng)/($sinAng^2-$cosAng^2) Local $left = ($iLW-$wid)/2 Local $ht = ($iLH*$cosAng-$iLW*$sinAng)/($cosAng^2-$sinAng^2) Local $top = ($iLH-$ht)/2 _GDIPlus_GraphicsDrawRect($ghGfxClone,$left,$top,$wid,$ht,$ghPen) ; temp _GDIPlus_GraphicsSetClipRect($ghGfxClone,$left,$top,$wid,$ht,0) _GDIPlus_GraphicsDispose($ghGfxClone) $ghGfxClone=_GDIPlus_ImageGetGraphicsContext($ghImage) _GDIPlus_GraphicsClear($ghImage) _GDIPlus_GraphicsDrawImageRect($ghGfxClone,$ghImageClone,0,0,$iW,$iH) _GDIPlus_GraphicsDispose($ghGfxClone) _GDIPlus_ImageDispose($ghImageClone) $gy0 = 400 $gy1 = 400 Paint() _GDIPlus_ImageSaveToFile($ghImage,'H:\b\2.jpg') ; added - is rotated, with same size as original file EndSwitch EndIf WEnd ; Clean up resources _GDIPlus_MatrixDispose($ghMatrix) _GDIPlus_ImageDispose($ghCanvas) _GDIPlus_ImageDispose($ghImage) _GDIPlus_ImageDispose($ghBitmap) _GDIPlus_PenDispose($ghPen) _GDIPlus_GraphicsDispose($gGraphicPic) _GDIPlus_Shutdown() EndFunc Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local Const $kYmax=$iLH-1,$kDelta=2 Local $vec = GUIGetCursorInfo($gForm1) If $vec[4] = $vec[4]=$glblPic Then Local $iDelta = BitShift($wParam, 16) ; positive = up Local $iKeys = _WinAPI_LoWord($wParam) If BitAND($iKeys,$MK_CONTROL)=$MK_CONTROL Then If BitAND($iKeys,$MK_SHIFT)=$MK_SHIFT Then ; do nothing Else If $iDelta > 0 And $gY0>3 Then $gY0 -= $kDelta If $iDelta < 0 And $gY0<$kYmax Then $gY0 += $kDelta EndIf Else If BitAND($iKeys,$MK_SHIFT)=$MK_SHIFT Then If $iDelta > 0 And $gY1>3 Then $gY1 -= $kDelta If $iDelta < 0 And $gY1<$kYmax Then $gY1 += $kDelta Else If $iDelta > 0 And $gY0>3 Then $gY0 -= $kDelta If $iDelta < 0 And $gY0<$kYmax Then $gY0 += $kDelta If $iDelta > 0 And $gY1>3 Then $gY1 -= $kDelta If $iDelta < 0 And $gY1<$kYmax Then $gY1 += $kDelta EndIf EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_MOUSEWHEEL Func Paint() _GDIPlus_GraphicsClear($ghCanvas,0) _GDIPlus_GraphicsDrawImageRect($ghCanvas, $ghImage, 0,0, $iLW, $iLH) _GDIPlus_GraphicsDrawLine($ghCanvas, $gX0, $gY0, $gX1, $gY1, $ghPen) _GDIPlus_GraphicsDrawImageRect($gGraphicPic, $ghBitmap, 0, 0, $iW, $iH) EndFunc Func WM_PAINT() _WinAPI_RedrawWindow($gForm1, 0, 0, $RDW_UPDATENOW) Paint() _WinAPI_RedrawWindow($gForm1, 0, 0, $RDW_VALIDATE) EndFunc Func Angle($y, $x) ;return value is in degree Local Const $fPi = ACos(-1), $fPi2 = ACos(-1) / 2, $fRad = 180 / $fPi Switch True Case ($x > 0) Return ATan($y / $x) * $fRad Case ($x < 0 And $y >= 0) Return ATan($y / $x + $fPi) * $fRad Case ($x < 0 And $y < 0) Return ATan($y / $x - $fPi) * $fRad Case ($x = 0 And $y > 0) Return $fPi2 * $fRad Case ($x = 0 And $y < 0) Return -$fPi2 * $fRad Case ($x = 0 And $y = 0) Return 0 EndSwitch EndFunc I also don't understand how the rotated picture gets displayed. There are graphics objects, graphics contexts and PDI+ bitmaps. How are they related?
      Help would be much appreciated.