Jump to content

_GDIPlus_GraphicsDrawImage and code sort


youtuber
 Share

Recommended Posts

$hImage = _GDIPlus_ImageLoadFromFile($aImageSave)
            $X1 = _GDIPlus_ImageGetWidth($hImage)
            $Y1 = _GDIPlus_ImageGetHeight($hImage)

            $X2 = _GDIPlus_ImageGetWidth($hImage)
            $Y2 = _GDIPlus_ImageGetHeight($hImage)
            $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage)
            $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
            ;$PicPreview = GUICtrlCreatePic("", 24, 152, 572, 268)
            _GDIPlus_GraphicsDrawImage ($hGraphic, 24, 152, 572, 268);?

I have the same size and relative coords to $PicPreview in the image placement form1 I want to be 

 

Other Responsibility Is there a problem with _GDIPlus code sorting?

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $Form1, $hImage, $hGraphic, $OpenPictures, $PicPreview
_GDIPlus_StartUp()
$Form1 = GUICreate("Form1", 615, 438, 374, 347)
$PicPreview = GUICtrlCreatePic("", 24, 152, 572, 268)
$ButtonPreview = GUICtrlCreateButton("Preview", 520, 112, 75, 25)
$InputImageDir = GUICtrlCreateInput("", 64, 48, 177, 21)
$ButtonOpen = GUICtrlCreateButton("...", 256, 48, 75, 25)
$ButtonWatermark = GUICtrlCreateButton("Watermark Add", 256, 112, 80, 25)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_ShutDown()
            Exit

        Case $ButtonOpen
            $OpenPictures = FileOpenDialog("Where are the pictures?", @ScriptDir & "\", "Picture format (*.jpg;*.bmp;*.png)", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
                If Not $OpenPictures Then
                    MsgBox(64, "İnfo","No Files Selected!",5)
                Else
                    GUICtrlSetData($InputImageDir,$OpenPictures)
                EndIf

        Case $ButtonWatermark
            $aImageLoad = $OpenPictures
            $aImageSave = @ScriptDir & "\Save.png"
            $aImageLogo = @ScriptDir & "\Logo.png"
            _Watermark($aImageSave, $aImageLoad, $aImageLogo)

        Case $ButtonPreview
            $hImage = _GDIPlus_ImageLoadFromFile($aImageSave)
            $X1 = _GDIPlus_ImageGetWidth($hImage)
            $Y1 = _GDIPlus_ImageGetHeight($hImage)

            $X2 = _GDIPlus_ImageGetWidth($hImage)
            $Y2 = _GDIPlus_ImageGetHeight($hImage)
            $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage)
            $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
            ;$PicPreview = GUICtrlCreatePic("", 24, 152, 572, 268)
            _GDIPlus_GraphicsDrawImage ($hGraphic, 24, 152, 572, 268)

    EndSwitch
WEnd


Func _Watermark($sFile2, $sFile, $sLogo)
    Local $hImage1, $hImage2, $hGraphic
    _GDIPlus_Startup ()
    $hImage1 = _GDIPlus_ImageLoadFromFile ($sFile)   ; image
    $X1 = _GDIPlus_ImageGetWidth ($hImage1)
    $Y1 = _GDIPlus_ImageGetHeight ($hImage1)
    $hImage2 = _GDIPlus_ImageLoadFromFile ($sLogo)  ; logo
    $X2 = _GDIPlus_ImageGetWidth ($hImage2)
    $Y2 = _GDIPlus_ImageGetHeight ($hImage2)

    $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1)
    _GDIPlus_GraphicsDrawImage ($hGraphic, $hImage2, 20, $Y1-$Y2-30)
    _GDIPlus_ImageSaveToFile ($hImage1, $sFile2)  ; image watermarked

    _GDIPlus_ImageDispose ($hImage1)
    _GDIPlus_ImageDispose ($hImage2)
    _GDIPlus_ShutDown ()
EndFunc   ;==>_Watermark

 

Edited by youtuber
Link to comment
Share on other sites

@youtuber if you want to add an image as watermark then you can have a look to

 

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

You mean that you want to resize the image to the control size - here 572 x 268? If yes, then you can use _GDIPlus_ImageResize before you send the image to the control.

Have in mind that the image must be in GDI format - _GDIPlus_ImageResize result is GDIPlus and thus you have to convert it to GDI first using _GDIPlus_BitmapCreateHBITMAPFromBitmap.

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

@UEZ Thank you

that is what I want
But is there a missing code?
Or is there a problem with the code sequence?

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $Form1, $hImage, $hGraphic
_GDIPlus_StartUp()
$hImage = _GDIPlus_BitmapCreateFromMemory(InetRead("https://www.autoitscript.com/images/favicon/favicon-180x180.png"))
$Form1 = GUICreate("Form1", 615, 438, 374, 347)
;$PicPreview = GUICtrlCreatePic("", 24, 152, 572, 268)
$ButtonPreview = GUICtrlCreateButton("Preview", 520, 112, 75, 25)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_ShutDown()
            Exit

        Case $ButtonPreview
             $hImg = _GDIPlus_ImageResize($hImage, 572, 268)
             $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage)
             $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
             _GDIPlus_GraphicsDrawImage ($hGraphic, $hImg, 24,152)
    EndSwitch
WEnd

 

Edited by youtuber
Link to comment
Share on other sites

Something like this here?

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $Form1, $hImage, $hGraphic
_GDIPlus_StartUp()
$hImage = _GDIPlus_BitmapCreateFromMemory(InetRead("https://www.autoitscript.com/images/favicon/favicon-180x180.png"))
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$Form1 = GUICreate("Form1", 615, 438, 374, 347)
;$PicPreview = GUICtrlCreatePic("", 24, 152, 572, 268)
$ButtonPreview = GUICtrlCreateButton("Preview", 520, 112, 75, 25)
GUISetState(@SW_SHOW)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
_GDIPlus_GraphicsSetInterpolationMode($hGraphic, 5)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_ShutDown()
            Exit
        Case $ButtonPreview
             _GDIPlus_GraphicsDrawImageRect ($hGraphic, $hImage, 24,32, $iW * 2, $iH * 2)
    EndSwitch
WEnd

 

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

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Form1, $hImage, $hGraphic, $iW, $iH, $iW_Prev, $iH_Prev, $PicPreview, $ButtonPreview, $iW_New, $iH_New, $iPrev_Min, $hBitmap_Prev, $hBitmapGDI_Prev
_GDIPlus_StartUp()
$hImage = _GDIPlus_BitmapCreateFromMemory(InetRead("https://www.autoitscript.com/images/favicon/favicon-180x180.png"))
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$iW_Prev = 512
$iH_Prev = 368
$Form1 = GUICreate("Form1", 615, 438, 374, 347)
$PicPreview = GUICtrlCreatePic("", 24, 32, $iW_Prev, $iH_Prev)
$ButtonPreview = GUICtrlCreateButton("Preview", 520, 112, 75, 25)
GUISetState(@SW_SHOW)

$iW_New = $iW_Prev / $iW
$iH_New = $iH_Prev / $iH
$iPrev_Min = $iW_New < $iH_New ? $iH_New : $iH_New
$hBitmap_Prev = _GDIPlus_ImageScale($hImage, $iPrev_Min, $iPrev_Min, 6)
$hBitmapGDI_Prev = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Prev)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_ImageDispose($hBitmap_Prev)
            _WinAPI_DeleteObject($hBitmapGDI_Prev)
            _GDIPlus_ShutDown()
            Exit
        Case $ButtonPreview
            _WinAPI_DeleteObject(GUICtrlSendMsg($PicPreview, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmapGDI_Prev))
    EndSwitch
WEnd

 

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

And where is the problem to change the values for GUICtrlCreatePic?

Have a look here

to have an example how to adjust image in preview section properly.

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

Did you change it to 

$iW_Prev = 572
$iH_Prev = 268
$Form1 = GUICreate("Form1", 615, 438, 374, 347)
$PicPreview = GUICtrlCreatePic("", 24, 152, $iW_Prev, $iH_Prev)

?

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

If you want the image stretched then try this:

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Form1, $hImage, $hGraphic, $iW, $iH, $iW_Prev, $iH_Prev, $PicPreview, $ButtonPreview, $iW_New, $iH_New, $iPrev_Min, $hBitmap_Prev, $hBitmapGDI_Prev
_GDIPlus_StartUp()
$hImage = _GDIPlus_BitmapCreateFromMemory(InetRead("https://www.autoitscript.com/images/favicon/favicon-180x180.png"))
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$iW_Prev = 572
$iH_Prev = 268
$Form1 = GUICreate("Form1", 615, 438, 374, 347)
$PicPreview = GUICtrlCreatePic("", 24, 152, $iW_Prev, $iH_Prev)
$ButtonPreview = GUICtrlCreateButton("Preview", 520, 112, 75, 25)
GUISetState(@SW_SHOW)

$hBitmap_Prev = _GDIPlus_ImageResize($hImage, $iW_Prev, $iH_Prev, 6)
$hBitmapGDI_Prev = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Prev)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_ImageDispose($hBitmap_Prev)
            _WinAPI_DeleteObject($hBitmapGDI_Prev)
            _GDIPlus_ShutDown()
            Exit
        Case $ButtonPreview
            _WinAPI_DeleteObject(GUICtrlSendMsg($PicPreview, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmapGDI_Prev))
    EndSwitch
WEnd

 

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

8 minutes ago, UEZ said:

If you want the image stretched then try this:

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Form1, $hImage, $hGraphic, $iW, $iH, $iW_Prev, $iH_Prev, $PicPreview, $ButtonPreview, $iW_New, $iH_New, $iPrev_Min, $hBitmap_Prev, $hBitmapGDI_Prev
_GDIPlus_StartUp()
$hImage = _GDIPlus_BitmapCreateFromMemory(InetRead("https://www.autoitscript.com/images/favicon/favicon-180x180.png"))
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$iW_Prev = 572
$iH_Prev = 268
$Form1 = GUICreate("Form1", 615, 438, 374, 347)
$PicPreview = GUICtrlCreatePic("", 24, 152, $iW_Prev, $iH_Prev)
$ButtonPreview = GUICtrlCreateButton("Preview", 520, 112, 75, 25)
GUISetState(@SW_SHOW)

$hBitmap_Prev = _GDIPlus_ImageResize($hImage, $iW_Prev, $iH_Prev, 6)
$hBitmapGDI_Prev = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Prev)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_ImageDispose($hBitmap_Prev)
            _WinAPI_DeleteObject($hBitmapGDI_Prev)
            _GDIPlus_ShutDown()
            Exit
        Case $ButtonPreview
            _WinAPI_DeleteObject(GUICtrlSendMsg($PicPreview, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmapGDI_Prev))
    EndSwitch
WEnd

 

Yes, that's what I want, but what's the difference?

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Form1, $hImage, $hGraphic
_GDIPlus_StartUp()
$hImage = _GDIPlus_BitmapCreateFromMemory(InetRead("https://www.autoitscript.com/images/favicon/favicon-180x180.png"))
$Form1 = GUICreate("Form1", 615, 438, 374, 347)
;$PicPreview = GUICtrlCreatePic("", 24, 152, 572, 268)
$ButtonPreview = GUICtrlCreateButton("Preview", 520, 112, 75, 25)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_ShutDown()
            Exit

        Case $ButtonPreview
             $hImg = _GDIPlus_ImageResize($hImage, 572, 268)
             $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage)
             $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
             _GDIPlus_GraphicsDrawImage ($hGraphic, $hImg, 24,152)
    EndSwitch
WEnd

 

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...