Sign in to follow this  
Followers 0
rootx

[SOLVED] _GDIPlus_ImageRotateFlip Overwrite file?

7 posts in this topic

#1 ·  Posted (edited)

#include <APIResConstants.au3>
#include <GuiTab.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GDIPlus.au3>

_imagelist()

Func _imagelist()

    Global $inimg = @ScriptDir&"\img.ini"

    Global $idListview, $hImage

    Local $aArray2 = _FileListToArrayRec("G:\Image", "*.jpg", $FLTAR_FILES, 1, $FLTAR_SORT,$FLTAR_FULLPATH)
    $fileArray4 = UBound($aArray2) -1
    If $fileArray4 > 0 Then
    $hGUI1 = GUICreate("Image Album List "&$fileArray4, 800, 600)
    $idListview = GUICtrlCreateListView("", 2, 2, 800, 600, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))

    ; block resizing of columns
    ControlDisable($hGUI1, "", HWnd(_GUICtrlListView_GetHeader($idListview)))

    GUISetState()
    ; Load images
    $hImage = _GUIImageList_Create(64, 64,5,3)
    _GUICtrlListView_SetImageList($idListview, $hImage)
    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Image", 64)
    _GUICtrlListView_AddColumn($idListview, "Path", 350)
    _GUICtrlListView_AddColumn($idListview, "Caption",365)
    ;_GUICtrlListView_HideColumn($idListview, 1)
    _GDIPlus_Startup()
    Local $GDIpBmpLarge,$GDIpBmpResized,$GDIbmp

    For $y = 1 To $fileArray4
        ;$ini = IniWrite($inimg,$aArray2[$y],"caption",$aArray2[$y]) ;<<< run only the first time, then put a comment
        $GDIpBmpLarge = _GDIPlus_ImageLoadFromFile($aArray2[$y]) ;GDI+ image!
        $GDIpBmpResized = _GDIPlus_ImageResize($GDIpBmpLarge, 64,64) ;GDI+ image
        $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResized) ;GDI image!
        $img = _GUIImageList_Add($hImage, $GDIbmp)
        _GUICtrlListView_SetImageList($idListview, $hImage, 1)
        ;Add items
        _GUICtrlListView_AddItem($idListview, StringRegExp($aArray2[$y], ".*\\(.+)$", 1), $img) ;image
        _GUICtrlListView_AddSubItem($idListview, $y-1,$aArray2[$y],1)
        _GUICtrlListView_AddSubItem($idListview, $y-1,IniRead($inimg,$aArray2[$y],"caption",""),2) ;caption
        ConsoleWrite($y&" "&$aArray2[$y]&@LF)
    Next

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    ;cleanup resources
    _GDIPlus_BitmapDispose($GDIpBmpLarge)
    _GDIPlus_BitmapDispose($GDIpBmpResized)
    _WinAPI_DeleteObject($GDIbmp)
    _GDIPlus_Shutdown()
    GUIDelete()
    Else
        MsgBox("","","Images folder are empty")
    EndIf
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $hWndListView = $idListview
    If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    $path = IniRead("cfg.ini","PAGE","sourcedir","")
                     Local $iItemText = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),2)
                     Local $sValue = InputBox("Edit Image", "Enter your description.", ""," M100",400,150)
                     Local $iIndex = _GUICtrlListView_GetSelectedIndices($idListview)
                     _GUICtrlListView_SetItemText($idListview,$iIndex,$sValue,2)
                      If $sValue <> "" Then
                         IniWrite($inimg,_GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),1),"caption",$sValue)
                      Else
                          _GUICtrlListView_SetItemText($idListview,$iIndex,$iItemText,3)
                      EndIf

                Case $LVN_COLUMNCLICK ; A column was clicked
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)

                    _GUICtrlListView_SortItems($idListview, _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),1))

                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _GDIPlus_Startup()
                    $image = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),1)
                    $newimg = StringRegExp(_GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),1), ".*\\", 1)[0]
                    $tempimg = "_new.jpg"
                    $hImage = _GDIPlus_ImageLoadFromFile($image)
                    $imgX = _GDIPlus_ImageGetWidth($hImage)
                    $imgY = _GDIPlus_ImageGetHeight($hImage)
                    _GDIPlus_ImageRotateFlip($hImage,2)

                    $hGUI = GUICreate($image, 801, 601, -1, -1);create a test gui to display the image
                    GUISetState(@SW_SHOW)
                    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
                    $hImage_new2 = _GDIPlus_ImageResize($hImage, 800,600)
                    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage_new2, 0, 0) ;display rotated image
                    _GDIPlus_ImageSaveToFile($hImage,$newimg&$tempimg)

                    ;cleanup resources
                    _GDIPlus_BitmapDispose($hImage)
                    _GDIPlus_BitmapDispose($hImage_new2)
                    _WinAPI_DeleteObject($newimg)
                    _WinAPI_DeleteObject($hGraphics)
                    _WinAPI_DeleteObject($hGUI)
                    _GDIPlus_Shutdown()

                    FileDelete($image)
                    FileMove($newimg&"\"&$tempimg,$image,1)

                    Return 0 ; allow the default processing
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

I would like to rotate a jpg and then overwrites the same jpg.

Why GDIplus keeps locked the file again.

THX

Edited by rootx

Share this post


Link to post
Share on other sites



Test this:

Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    $image = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),1)
                    $newimg = StringRegExp(_GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),1), ".*\\", 1)[0]
                    $tempimg = "_new.jpg"
                    $hImage = _GDIPlus_ImageLoadFromFile($image)
                    $imgX = _GDIPlus_ImageGetWidth($hImage)
                    $imgY = _GDIPlus_ImageGetHeight($hImage)
                    $himage_Clone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $imgX, $imgY,  $GDIP_PXF32ARGB)
                    _GDIPlus_ImageDispose($hImage)
                    _GDIPlus_ImageRotateFlip($himage_Clone,2)

                    $hGUI = GUICreate($image, 801, 601, -1, -1);create a test gui to display the image
                    GUISetState(@SW_SHOW)
                    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
                    $hImage_new2 = _GDIPlus_ImageResize($himage_Clone, 800,600)
                    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage_new2, 0, 0) ;display rotated image
                    _GDIPlus_ImageSaveToFile($himage_Clone,$newimg&$tempimg)

                    ;cleanup resources
                    _GDIPlus_ImageDispose($himage_Clone)
                    _GDIPlus_BitmapDispose($hImage_new2)
                    _WinAPI_DeleteObject($newimg)
                    _WinAPI_DeleteObject($hGraphics)
                    _WinAPI_DeleteObject($hGUI)

                    FileDelete($image)
                    FileMove($newimg&"\"&$tempimg,$image,1)

                    Return 0 ; allow the default processing

 


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

THX UEZ, but it does not work. The image is still blocked in the listview, also the cloned image is locked.

Share this post


Link to post
Share on other sites

This works for me - the image will be saved properly.

#include <GDIPlus.au3>

$image = @ScriptDir & "\Trapezoid.png"
 ;replace it with your image

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($image)
$imgX = _GDIPlus_ImageGetWidth($hImage)
$imgY = _GDIPlus_ImageGetHeight($hImage)
$himage_Clone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $imgX, $imgY,  $GDIP_PXF32ARGB)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ImageRotateFlip($himage_Clone,2)

$hGUI = GUICreate($image, 801, 601, -1, -1);create a test gui to display the image
GUISetState(@SW_SHOW)

Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
$hImage_new2 = _GDIPlus_ImageResize($himage_Clone, 800,600)
_GDIPlus_GraphicsDrawImage($hGraphics, $hImage_new2, 0, 0) ;display rotated image
ConsoleWrite(_GDIPlus_ImageSaveToFile($himage_Clone,$image) & @CRLF)

Do
Until GUIGetMsg() = -3

;cleanup resources
_GDIPlus_ImageDispose($himage_Clone)
_GDIPlus_BitmapDispose($hImage_new2)
_GDIPlus_Shutdown()

 


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

THX UEZ, I try it and work fine, if I do not load images from an array... like this

#include <APIResConstants.au3>
#include <GuiTab.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GDIPlus.au3>

$hGUI1 = GUICreate("Image Album List ", 800, 600)
$idListview = GUICtrlCreateListView("", 2, 2, 800, 600, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
$hImage = _GUIImageList_Create(64, 64,5,3)
_GUICtrlListView_SetImageList($idListview, $hImage)
; Add columns
_GUICtrlListView_AddColumn($idListview, "Image", 64)

GUISetState()
        _GDIPlus_Startup()
        $image = @ScriptDir & "\Trapezoid.png"
        $GDIpBmpLarge = _GDIPlus_ImageLoadFromFile($image) ;GDI+ image!
        $GDIpBmpResized = _GDIPlus_ImageResize($GDIpBmpLarge, 64,64) ;GDI+ image
        $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResized) ;GDI image!
        $img = _GUIImageList_Add($hImage, $GDIbmp)
        _GUICtrlListView_SetImageList($idListview, $hImage, 1)
        ;Add items
        _GUICtrlListView_AddItem($idListview, @ScriptDir & "\Trapezoid.png", $img) ;image
        _GUICtrlListView_AddSubItem($idListview, 1,@ScriptDir & "\Trapezoid.png",1)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    ;cleanup resources
    _GDIPlus_BitmapDispose($GDIpBmpLarge)
    _GDIPlus_BitmapDispose($GDIpBmpResized)
    _WinAPI_DeleteObject($GDIbmp)
    _GDIPlus_Shutdown()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $hWndListView = $idListview
    If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode

                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _GDIPlus_Startup()
                    $image2 = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),-1)
                    MsgBox("","",$image2)
                    $hImage = _GDIPlus_ImageLoadFromFile($image2)
                    $imgX = _GDIPlus_ImageGetWidth($hImage)
                    $imgY = _GDIPlus_ImageGetHeight($hImage)
                    $himage_Clone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $imgX, $imgY,  $GDIP_PXF32ARGB)
                    _GDIPlus_ImageDispose($hImage)
                    _GDIPlus_ImageRotateFlip($himage_Clone,2)

                    $hGUI = GUICreate($image2, 801, 601, -1, -1);create a test gui to display the image
                    GUISetState(@SW_SHOW)

                    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
                    $hImage_new2 = _GDIPlus_ImageResize($himage_Clone, 800,600)
                    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage_new2, 0, 0) ;display rotated image
                    MsgBox("","",$image)
                    _GDIPlus_ImageSaveToFile($himage_Clone,$image) ;$image.......work in this case
                    ;cleanup resources
                    _GDIPlus_ImageDispose($himage_Clone)
                    _GDIPlus_BitmapDispose($hImage_new2)
                    _GDIPlus_Shutdown()

                    Return 0 ; allow the default processing
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

why this does not happen when the listview is loaded from an array

#include <APIResConstants.au3>
#include <GuiTab.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GDIPlus.au3>

_imagelist()

Func _imagelist()

    Global $inimg = @ScriptDir&"\img.ini"

    Global $idListview, $hImage

    Local $aArray2 = _FileListToArrayRec("C:\Album", "*.jpg", $FLTAR_FILES, 1, $FLTAR_SORT,$FLTAR_FULLPATH)
    $fileArray4 = UBound($aArray2) -1
    If $fileArray4 > 0 Then
    $hGUI1 = GUICreate("Image Album List "&$fileArray4, 800, 600)
    $idListview = GUICtrlCreateListView("", 2, 2, 800, 600, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))

    ; block resizing of columns
    ControlDisable($hGUI1, "", HWnd(_GUICtrlListView_GetHeader($idListview)))

    GUISetState()
    ; Load images
    $hImage = _GUIImageList_Create(64, 64,5,3)
    _GUICtrlListView_SetImageList($idListview, $hImage)
    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Image", 64)
    _GUICtrlListView_AddColumn($idListview, "Path", 350)
    _GUICtrlListView_AddColumn($idListview, "Caption",365)
    ;_GUICtrlListView_HideColumn($idListview, 1)
    _GDIPlus_Startup()
    Local $GDIpBmpLarge,$GDIpBmpResized,$GDIbmp

    For $y = 1 To $fileArray4
        $ini = IniWrite($inimg,$aArray2[$y],"caption",$aArray2[$y]) ;<<< run only the first time, then put a comment
        $GDIpBmpLarge = _GDIPlus_ImageLoadFromFile($aArray2[$y]) ;GDI+ image!
        $GDIpBmpResized = _GDIPlus_ImageResize($GDIpBmpLarge, 64,64) ;GDI+ image
        $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResized) ;GDI image!
        $img = _GUIImageList_Add($hImage, $GDIbmp)
        _GUICtrlListView_SetImageList($idListview, $hImage, 1)
        ;Add items
        _GUICtrlListView_AddItem($idListview, StringRegExp($aArray2[$y], ".*\\(.+)$", 1), $img) ;image
        _GUICtrlListView_AddSubItem($idListview, $y-1,$aArray2[$y],1)
        _GUICtrlListView_AddSubItem($idListview, $y-1,IniRead($inimg,$aArray2[$y],"caption",""),2) ;caption
        ConsoleWrite($y&" "&$aArray2[$y]&@LF)
    Next

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    ;cleanup resources
    _GDIPlus_BitmapDispose($GDIpBmpLarge)
    _GDIPlus_BitmapDispose($GDIpBmpResized)
    _WinAPI_DeleteObject($GDIbmp)
    _GDIPlus_Shutdown()
    GUIDelete()
    Else
        MsgBox("","","Images folder are empty")
    EndIf
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $hWndListView = $idListview
    If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _GDIPlus_Startup()
                    $image2 = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),1)
                    MsgBox("","",$image2)
                    $hImage = _GDIPlus_ImageLoadFromFile($image2)
                    $imgX = _GDIPlus_ImageGetWidth($hImage)
                    $imgY = _GDIPlus_ImageGetHeight($hImage)
                    $himage_Clone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $imgX, $imgY,  $GDIP_PXF32ARGB)
                    _GDIPlus_ImageDispose($hImage)
                    _GDIPlus_ImageRotateFlip($himage_Clone,2)

                    $hGUI = GUICreate($image2, 801, 601, -1, -1);create a test gui to display the image
                    GUISetState(@SW_SHOW)

                    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
                    $hImage_new2 = _GDIPlus_ImageResize($himage_Clone, 800,600)
                    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage_new2, 0, 0) ;display rotated image
                     MsgBox("","Correct path image but...????",$image2)
                    _GDIPlus_ImageSaveToFile($himage_Clone,$image2);
                    ;cleanup resources
                    _GDIPlus_ImageDispose($himage_Clone)
                    _GDIPlus_BitmapDispose($hImage_new2)
                    _GDIPlus_Shutdown()

                    Return 0 ; allow the default processing
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Share this post


Link to post
Share on other sites

You are not releasing the GDI+ resources within your loop:

For $y = 1 To $fileArray4
        $ini = IniWrite($inimg,$aArray2[$y],"caption",$aArray2[$y]) ;<<< run only the first time, then put a comment
        $GDIpBmpLarge = _GDIPlus_ImageLoadFromFile($aArray2[$y]) ;GDI+ image!
        $GDIpBmpResized = _GDIPlus_ImageResize($GDIpBmpLarge, 64,64) ;GDI+ image
        $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResized) ;GDI image!
        $img = _GUIImageList_Add($hImage, $GDIbmp)
        _GUICtrlListView_SetImageList($idListview, $hImage, 1)
        ;Add items
        _GUICtrlListView_AddItem($idListview, StringRegExp($aArray2[$y], ".*\\(.+)$", 1), $img) ;image
        _GUICtrlListView_AddSubItem($idListview, $y-1,$aArray2[$y],1)
        _GUICtrlListView_AddSubItem($idListview, $y-1,IniRead($inimg,$aArray2[$y],"caption",""),2) ;caption
        ConsoleWrite($y&" "&$aArray2[$y]&@LF)
    Next

Check out the examples provided by LarsJ. ;)


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

Nooo !!! thanks Uez....:sweating: Perfect!

I upload the complete code maybe it could be useful to someone in the future.

#include <APIResConstants.au3>
#include <GuiTab.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GDIPlus.au3>

_imagelist()

Func _imagelist()

    Global $inimg = @ScriptDir&"\img.ini"

    Global $idListview, $hImage

    Local $aArray2 = _FileListToArrayRec("G:\Album", "*.jpg", $FLTAR_FILES, 1, $FLTAR_SORT,$FLTAR_FULLPATH)
    $fileArray4 = UBound($aArray2) -1
    If $fileArray4 > 0 Then
    $hGUI1 = GUICreate("Image Album List "&$fileArray4, 800, 600)
    $idListview = GUICtrlCreateListView("", 2, 2, 800, 600, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))

    ; block resizing of columns
    ControlDisable($hGUI1, "", HWnd(_GUICtrlListView_GetHeader($idListview)))

    GUISetState()
    ; Load images
    $hImage = _GUIImageList_Create(64, 64,5,3)
    _GUICtrlListView_SetImageList($idListview, $hImage)
    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Image", 64)
    _GUICtrlListView_AddColumn($idListview, "Path", 350)
    _GUICtrlListView_AddColumn($idListview, "Caption",365)
    ;_GUICtrlListView_HideColumn($idListview, 1)
    _GDIPlus_Startup()
    Local $GDIpBmpLarge,$GDIpBmpResized,$GDIbmp

    For $y = 1 To $fileArray4
        $ini = IniWrite($inimg,$aArray2[$y],"caption",$aArray2[$y]) ;<<< run only the first time, then put a comment
        $GDIpBmpLarge = _GDIPlus_ImageLoadFromFile($aArray2[$y]) ;GDI+ image!
        $GDIpBmpResized = _GDIPlus_ImageResize($GDIpBmpLarge, 64,64) ;GDI+ image
        $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResized) ;GDI image!
        $img = _GUIImageList_Add($hImage, $GDIbmp)
        _GUICtrlListView_SetImageList($idListview, $hImage, 1)
        ;Add items
        _GUICtrlListView_AddItem($idListview, StringRegExp($aArray2[$y], ".*\\(.+)$", 1), $img) ;load image inside listview
        _GUICtrlListView_AddSubItem($idListview, $y-1,$aArray2[$y],1)
        _GUICtrlListView_AddSubItem($idListview, $y-1,IniRead($inimg,$aArray2[$y],"caption",""),2) ;load caption inside listview
        _GDIPlus_BitmapDispose($GDIpBmpLarge) ;release GDI+ image!
        _GDIPlus_BitmapDispose($GDIpBmpResized);release GDI+ image!
        _WinAPI_DeleteObject($GDIbmp);release Obj!
    Next

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    ;cleanup resources
    _GDIPlus_Shutdown()
    GUIDelete()
    Else
        MsgBox("","","Images folder are empty")
    EndIf
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $hWndListView = $idListview
    If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    $path = IniRead("cfg.ini","PAGE","sourcedir","")
                     Local $iItemText = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),2)
                     Local $sValue = InputBox("Edit Image", "Enter your description.", ""," M100",400,150)
                     Local $iIndex = _GUICtrlListView_GetSelectedIndices($idListview)
                     _GUICtrlListView_SetItemText($idListview,$iIndex,$sValue,2)
                      If $sValue <> "" Then
                         IniWrite($inimg,_GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),1),"caption",$sValue)
                      Else
                          _GUICtrlListView_SetItemText($idListview,$iIndex,$iItemText,3)
                      EndIf

                Case $LVN_COLUMNCLICK ; A column was clicked
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)

                    _GUICtrlListView_SortItems($idListview, _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),1))

                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _GDIPlus_Startup()
                    $image2 = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"),1)
                    $hImage = _GDIPlus_ImageLoadFromFile($image2)
                    $imgX = _GDIPlus_ImageGetWidth($hImage)
                    $imgY = _GDIPlus_ImageGetHeight($hImage)
                    $himage_Clone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $imgX, $imgY,  $GDIP_PXF32ARGB)
                    _GDIPlus_ImageDispose($hImage)
                    _GDIPlus_ImageRotateFlip($himage_Clone,2)
                    $hGUI = GUICreate($image2, 801, 601, -1, -1);create a test gui to display the image
                    GUISetState(@SW_SHOW)
                    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
                    $hImage_new2 = _GDIPlus_ImageResize($himage_Clone, 800,600)
                    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage_new2, 0, 0) ;display rotated image
                    _GDIPlus_ImageSaveToFile($himage_Clone,$image2);
                    ;cleanup resources
                    _GDIPlus_ImageDispose($hImage)
                    _GDIPlus_ImageDispose($himage_Clone)
                    _GDIPlus_BitmapDispose($hImage_new2)
                    _WinAPI_DeleteObject($hGraphics)
                    _GDIPlus_Shutdown()

                    Return 0 ; allow the default processing
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

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
Sign in to follow this  
Followers 0