Jump to content

Recommended Posts

Posted (edited)

my source is.... screencapture don't work.  rotate don't work.  help me

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=0.0.0.79
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <SendMessage.au3>
#include <ScreenCapture.au3>
#include <Constants.au3>

;Opt("MustDeclareVars", 1)

;Global $hBitmap, $hImage, $hImage_new, $sCLSID, $tData, $tParams

Local $Form = GUICreate("Picture Test", 500, 500)

local $labpic = GUICtrlCreateLabel("",9,9,302,302,$SS_BLACKFRAME)
GUICtrlSetState(-1, $GUI_DISABLE)

Local $Pic = GUICtrlCreatePic("", 10, 10, 300, 300)

Local $btnCapture = GUICtrlCreateButton("스크린 캡쳐",320,10,80,30)

local $btnLoadImage = GUICtrlCreateButton("이미지 로드",405,10,80,30)

local $btnRotateImage = GUICtrlCreateButton("이미지 회전",320,45,80,30)

GUISetState(@SW_SHOW)


While 1

  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      ExitLoop

      Case $btnCapture ;스크린 캡쳐 버튼 클릭할 경우

          Screen_Capture();스크린 캡쳐 함수 실행

      case $btnLoadImage ;이미지 로드 버튼을 클릭한 경우

          Load_Image(); 이미지 로드 함수 실행

      case $btnRotateImage ;이미지회전 버튼을 클릭한 경우

          Rotate_Image();이미지 회전 함수 실행

  EndSwitch
WEnd

GUIDelete($Form)

; ============================================
Func Screen_Capture()

 _GDIPlus_Startup()
 $hBitmap2 = _ScreenCapture_Capture("", 100, 100, 300, 300, False) ; 200 x 200
 ;$hBitmap2 = _ScreenCapture_Capture("", 100, 100, 400, 400,True) ; 200 x 200
 $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)
 $hImage = _GDIPlus_ImageResize($hImage2, 300, 300) ; resize to 300 x 300
 $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

 _SetBitmapToCtrl($Pic, $hBitmap)

 ;Clean up and shutdown GDIPlus.
 _GDIPlus_ImageDispose($hImage)
 _GDIPlus_ImageDispose($hImage2)
 _WinAPI_DeleteObject($hBitmap)
 _WinAPI_DeleteObject($hBitmap2)
 _GDIPlus_Shutdown()

EndFunc

Func _SetBitmapToCtrl($CtrlId, $hBitmap)
  Local Const $SS_IMAGE_BITMAP = 0

  Local $hWnd = GUICtrlGetHandle($CtrlId)
  If $hWnd = 0 Then Return SetError(1, 0, 0)

  _SendMessage($hWnd, $STM_SETIMAGE, $SS_IMAGE_BITMAP, $hBitmap)
  If @error Then Return SetError(4, 0, 0)
  Return 1

EndFunc   ;==>_SetBitmapToCtrl

;==========================================================================================================================================================
;func Load_Image()

  ;  _GDIPlus_Startup() ; Initialize GDI+ library
  ; $hOrigSS = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\1.jpg")     ; Capture 32 bit bitmap and return a bitmap image object
  ; $hClip = _GDIPlus_BitmapCloneArea($hOrigSS,  0, 0, 300, 300) ; Clip out area of bitmap object; left,top,width,height
  ; $hResize = _GDIPlus_ImageScale($hClip,1,1) ; Enlarge width & height
   ;$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hOrigSS) ; Create bitmap object from bitmap handle

  ; $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic)) ; Get the winhandle of the control holding the image and create Graphics Object
  ; _GDIPlus_GraphicsDrawImage($hGraphic, $hResize,0,0) ; Paste the picture into the control holding the image

  ; _GDIPlus_GraphicsDispose($hGraphic) ; Clean up resources
   ;_GDIPlus_BitmapDispose($hBitmap)
  ; _WinAPI_DeleteObject($hOrigSS)
  ; _GDIPlus_Shutdown() ; Shut down GDI+ library
;EndFunc
;=======================================================================================================================================================

Func Load_Image($FileName = @ScriptDir & "\05_PictureBox1_ex.jpg") ;해당이미지를 Picture 컨트롤 사이즈에 맞혀 로드한다.

  _GDIPlus_Startup()
  ;$g_hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\05_PictureBox1_ex.jpg")
   $g_hImage = _GDIPlus_ImageLoadFromFile($FileName)
  $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic))
  _GDIPlus_GraphicsDrawImageRect($hGraphic, $g_hImage, 0, 0, 300, 300)
  _GDIPlus_GraphicsDispose($hGraphic)
  _WinAPI_DeleteObject($g_hImage)
  _GDIPlus_Shutdown()

EndFunc ;==>Load_Image

Func Rotate_Image($FileName2 = @ScriptDir & "\05_PictureBox1_ex.jpg",$flagFilp = 1)
    ;$flagfilp = 1 이면 90도 회전, 2면 180도 회전, 3이면 270도 회전

   _GDIPlus_StartUp()

 $hImage = _GDIPlus_ImageLoadFromFile($FileName2)
 $hImage_new = _GDIPlus_ImageResize($hImage, 600, 600) ;resize image
 _GDIPlus_ImageRotateFlip($hImage_new, $flagFilp)
 _GDIPlus_ImageSaveToFile($hImage_new, @TempDir & "\rotate.jpg")
 _GDIPlus_ImageDispose($hImage)
 _GDIPlus_ImageDispose($hImage_new)
 _GDIPlus_ShutDown()

  Load_Image(@TempDir & "\rotate.jpg")

EndFunc

 

Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites

"Don't work" should be removed from the English language. WHAT is your desired outcome? WHAT are you seeing instead? At WHAT point in your code is it failing (you have ZERO error checking)? WHAT errors are you receiving? WHAT have you done to troubleshoot those errors? Help us help you.


"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
Posted (edited)

In the case of ScreenCapture, a black screen appears when executed. For Rotate, it works only with flag 1 in the function, not the rest.

Edited by Melba23
Reduced font size

Share this post


Link to post
Share on other sites
Posted (edited)

Here, with autoit3 (v3.3.14.3) the screen capture is working, (i'v added the rotation to the capture, as a test)

rotation is working as well (demonstrated by a new gui which is displaying the rotated image. 

The function _GDIPlus_ImageSaveToFile does nothing. (even the example file (_GDIPlus_ImageSaveToFile.au3/_GDIPlus_ImageSaveToFileEx.au3) from autoit help does not save the picture, and i have changed the folder, to make sure that the script can write to it).

Here is the halbum2040's source (translated to english) with added test gui for rotation.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=0.0.0.82
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <SendMessage.au3>
#include <ScreenCapture.au3>
#include <Constants.au3>

;Opt("MustDeclareVars", 1)

;Global $hBitmap, $hImage, $hImage_new, $sCLSID, $tData, $tParams

Local $Form = GUICreate("Picture Test", 500, 500)

Local $labpic = GUICtrlCreateLabel("", 9, 9, 302, 302, $SS_BLACKFRAME)
GUICtrlSetState(-1, $GUI_DISABLE)

Local $Pic = GUICtrlCreatePic("", 10, 10, 300, 300)

Local $btnCapture = GUICtrlCreateButton("screen capture", 320, 10, 80, 30)

Local $btnLoadImage = GUICtrlCreateButton("Load image", 405, 10, 80, 30)

Local $btnRotateImage = GUICtrlCreateButton("Rotate image", 320, 45, 80, 30)

GUISetState(@SW_SHOW)


While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $btnCapture ;When clicking on the screen capture button

            Screen_Capture() ; Execute screen capture function

        Case $btnLoadImage ;if you click the Load Image button

            Load_Image() ; Execute image load function

        Case $btnRotateImage ;if you click the rotate image button

            Rotate_Image() ; Execute image rotation function

    EndSwitch
WEnd

GUIDelete($Form)

; ============================================
Func Screen_Capture()

    _GDIPlus_Startup()
    $hBitmap2 = _ScreenCapture_Capture("", 100, 100, 300, 300, False) ; 200 x 200
    ;$hBitmap2 = _ScreenCapture_Capture("", 100, 100, 400, 400,True) ; 200 x 200
    $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)
    $hImage = _GDIPlus_ImageResize($hImage2, 300, 300) ; resize to 300 x 300
    _GDIPlus_ImageRotateFlip($hImage, 2)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

    _SetBitmapToCtrl($Pic, $hBitmap)

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage2)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteObject($hBitmap2)
    _GDIPlus_Shutdown()

EndFunc   ;==>Screen_Capture

Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $SS_IMAGE_BITMAP = 0

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)

    _SendMessage($hWnd, $STM_SETIMAGE, $SS_IMAGE_BITMAP, $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    Return 1

EndFunc   ;==>_SetBitmapToCtrl

;==========================================================================================================================================================
;func Load_Image()

;  _GDIPlus_Startup() ; Initialize GDI+ library
; $hOrigSS = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\1.jpg")     ; Capture 32 bit bitmap and return a bitmap image object
; $hClip = _GDIPlus_BitmapCloneArea($hOrigSS,  0, 0, 300, 300) ; Clip out area of bitmap object; left,top,width,height
; $hResize = _GDIPlus_ImageScale($hClip,1,1) ; Enlarge width & height
;$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hOrigSS) ; Create bitmap object from bitmap handle

; $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic)) ; Get the winhandle of the control holding the image and create Graphics Object
; _GDIPlus_GraphicsDrawImage($hGraphic, $hResize,0,0) ; Paste the picture into the control holding the image

; _GDIPlus_GraphicsDispose($hGraphic) ; Clean up resources
;_GDIPlus_BitmapDispose($hBitmap)
; _WinAPI_DeleteObject($hOrigSS)
; _GDIPlus_Shutdown() ; Shut down GDI+ library
;EndFunc
;=======================================================================================================================================================

Func Load_Image($FileName = @ScriptDir & "\05_PictureBox1_ex.jpg") ; Load the image to fit the picture control size.

    _GDIPlus_Startup()
    ;$g_hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\05_PictureBox1_ex.jpg")
    $g_hImage = _GDIPlus_ImageLoadFromFile($FileName)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic))
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $g_hImage, 0, 0, 300, 300)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($g_hImage)
    _GDIPlus_Shutdown()

EndFunc   ;==>Load_Image

Func Rotate_Image($FileName2 = @ScriptDir & "\05_PictureBox1_ex.jpg", $flagFilp = 4)
    ;$flagfilp = 1 rotates 90 degrees, 2 rotates 180 degrees, 3 rotates 270 degrees

    _GDIPlus_Startup()

    $hImage = _GDIPlus_ImageLoadFromFile($FileName2)
    $hImage_new = _GDIPlus_ImageResize($hImage, 600, 600) ;resize image
    _GDIPlus_ImageRotateFlip($hImage_new, $flagFilp)

    Local $hGUI = GUICreate("GDI+ test", 800, 600, -1, -1) ;create a test gui to display the rotated image
    GUISetState(@SW_SHOW)

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage_new, 0, 0) ;display rotated image
    While GUIGetMsg() <> $GUI_EVENT_CLOSE
    WEnd
    GUIDelete($hGUI)
    If _GDIPlus_ImageSaveToFile($hImage_new, @TempDir & "\rotate.jpg")=False Then
        Local $er=@error
        Local $ex=@extended
        CW("ImageSaveError " & $er & " / " & $ex )
    EndIf

    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage_new)
    _GDIPlus_Shutdown()

    Load_Image(@TempDir & "\rotate.jpg")

EndFunc   ;==>Rotate_Image

Func cw($txt)
    ConsoleWrite($txt & @CRLF)
EndFunc   ;==>cw

If you run the code, the rotate image does show a rotated image, but the ImageSave fails with @error set to -1 and @extendend set to 0

 

Edited by Dan_555

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

Share this post


Link to post
Share on other sites

Dan_555,

Quote

 with autoit3 (v3.3.14.3) 

I suggest upgrading to 3.3.14.5:

As you can see ScreenCapture was one of the affected functions.

M23


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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Dan_555, 

Thank you very much. I am very happy to add and annotate the functions in the code. 
However, the Rotate function does not work properly. 
If you put another value in the flag in the Rotate function, the change does not occur. 
Thank you again for your concern.

Share this post


Link to post
Share on other sites
Posted (edited)

Please check if this code does the rotation:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=0.0.0.82
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <SendMessage.au3>
#include <ScreenCapture.au3>
#include <Constants.au3>
#include <Array.au3>
;Opt("MustDeclareVars", 1)

;Global $hBitmap, $hImage, $hImage_new, $sCLSID, $tData, $tParams

Local $Form = GUICreate("Picture Test", 500, 500)

Local $labpic = GUICtrlCreateLabel("", 9, 9, 302, 302, $SS_BLACKFRAME)
GUICtrlSetState(-1, $GUI_DISABLE)

Local $Pic = GUICtrlCreatePic("", 10, 10, 300, 300)

Local $btnCapture = GUICtrlCreateButton("screen capture", 320, 10, 80, 30)

Local $btnLoadImage = GUICtrlCreateButton("Load image", 405, 10, 80, 30)

Local $btnRotateImage = GUICtrlCreateButton("Rotate image", 320, 45, 80, 30)

GUISetState(@SW_SHOW)


While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $btnCapture ;When clicking on the screen capture button

            Screen_Capture() ; Execute screen capture function

        Case $btnLoadImage ;if you click the Load Image button

            Load_Image() ; Execute image load function

        Case $btnRotateImage ;if you click the rotate image button
            For $X = 0 To 9
                Rotate_Image(@ScriptDir & "\05_PictureBox1_ex.jpg", $X) ; Execute image rotation function
                Sleep(250)
            Next
    EndSwitch
WEnd

GUIDelete($Form)

; ============================================
Func Screen_Capture()

    _GDIPlus_Startup()
    $hBitmap2 = _ScreenCapture_Capture("", 100, 100, 300, 300, False) ; 200 x 200
    ;$hBitmap2 = _ScreenCapture_Capture("", 100, 100, 400, 400,True) ; 200 x 200
    $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)
    $hImage = _GDIPlus_ImageResize($hImage2, 300, 300) ; resize to 300 x 300
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

    _SetBitmapToCtrl($Pic, $hBitmap)

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage2)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteObject($hBitmap2)
    _GDIPlus_Shutdown()

EndFunc   ;==>Screen_Capture

Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $SS_IMAGE_BITMAP = 0

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)

    _SendMessage($hWnd, $STM_SETIMAGE, $SS_IMAGE_BITMAP, $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    Return 1

EndFunc   ;==>_SetBitmapToCtrl

;==========================================================================================================================================================
;func Load_Image()

;  _GDIPlus_Startup() ; Initialize GDI+ library
; $hOrigSS = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\1.jpg")     ; Capture 32 bit bitmap and return a bitmap image object
; $hClip = _GDIPlus_BitmapCloneArea($hOrigSS,  0, 0, 300, 300) ; Clip out area of bitmap object; left,top,width,height
; $hResize = _GDIPlus_ImageScale($hClip,1,1) ; Enlarge width & height
;$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hOrigSS) ; Create bitmap object from bitmap handle

; $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic)) ; Get the winhandle of the control holding the image and create Graphics Object
; _GDIPlus_GraphicsDrawImage($hGraphic, $hResize,0,0) ; Paste the picture into the control holding the image

; _GDIPlus_GraphicsDispose($hGraphic) ; Clean up resources
;_GDIPlus_BitmapDispose($hBitmap)
; _WinAPI_DeleteObject($hOrigSS)
; _GDIPlus_Shutdown() ; Shut down GDI+ library
;EndFunc
;=======================================================================================================================================================

Func Load_Image($FileName = @ScriptDir & "\05_PictureBox1_ex.jpg") ; Load the image to fit the picture control size.

    _GDIPlus_Startup()
    ;$g_hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\05_PictureBox1_ex.jpg")
    $g_hImage = _GDIPlus_ImageLoadFromFile($FileName)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic))
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $g_hImage, 0, 0, 300, 300)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($g_hImage)
    _GDIPlus_Shutdown()

EndFunc   ;==>Load_Image

Func Rotate_Image($FileName2 = @ScriptDir & "\05_PictureBox1_ex.jpg", $flagFilp = 2)
    ;$flagfilp = 1 rotates 90 degrees, 2 rotates 180 degrees, 3 rotates 270 degrees

    _GDIPlus_Startup()

    $hImage = _GDIPlus_ImageLoadFromFile($FileName2)
    $hImage_new = _GDIPlus_ImageResize($hImage, 600, 600) ;resize image
    _GDIPlus_ImageRotateFlip($hImage_new, $flagFilp)

;~  Local $hGUI = GUICreate("GDI+ test", 800, 600, -1, -1) ;create a test gui to display the rotated image
;~  GUISetState(@SW_SHOW)

;~  Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
;~  _GDIPlus_GraphicsDrawImage($hGraphics, $hImage_new, 0, 0) ;display rotated image
;~  While GUIGetMsg() <> $GUI_EVENT_CLOSE
;~  WEnd
;~  GUIDelete($hGUI)
    $ftemp = @TempDir & "\rotate" & $flagFilp & ".jpg"
    If FileExists($ftemp) Then
        If FileDelete($ftemp) = 0 Then cw("could not delete")
    EndIf
    If _GDIPlus_ImageSaveToFile($hImage_new, $ftemp) = False Then
        Local $er = @error
        Local $ex = @extended
        cw("ImageSaveError " & $er & " / " & $ex & " $flag= " & $flagFilp)
    EndIf

    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage_new)
    _GDIPlus_Shutdown()

    Load_Image($ftemp)

EndFunc   ;==>Rotate_Image

Func cw($txt)
    ConsoleWrite($txt & @CRLF)
EndFunc   ;==>cw

If it does the 1st time at your pc, then the problem is easily identified.

check the console output, when you run it (i mean clicking the rotation button)  the second/3rd time.

 

Edit: This should unlock the locked file:

Func Load_Image($FileName = @ScriptDir & "\05_PictureBox1_ex.jpg") ; Load the image to fit the picture control size.

    _GDIPlus_Startup()
    ;$g_hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\05_PictureBox1_ex.jpg")
    $g_hImage = _GDIPlus_ImageLoadFromFile($FileName)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic))
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $g_hImage, 0, 0, 300, 300)
    _GDIPlus_ImageDispose($g_hImage)                                        ;<------- adition
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($g_hImage)
    _GDIPlus_Shutdown()

EndFunc   ;==>Load_Image

 

Edited by Dan_555

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

Share this post


Link to post
Share on other sites

Dan_555, this solution also helped me a lot. 
The moving part of Rotate is really fantastic for me. 
Writing your code seems to have been the basis for writing my code. 
I don't mind, but I have a question. 
I am curious to see if I can implement the function to save the screen captured image. 
I'm very curious what code to put out if you can.

Share this post


Link to post
Share on other sites
Posted (edited)

Hmm, the whole code is yours. I'v only added some minor changes.

The rotating image was only to identify where the bug is, which would prevent the new images to appear or to be saved. (i leaved it there, because i wanted you to test it, but few minutes after the posting, i found the solution)

To save a captured screenshot, you can use:

_ScreenCapture_Capture(@TempDir & "\screenshot.jpg", 100, 100, 300, 300, False)

(and then load it).

 

P.S. I have a project (well someone (from this forum) left it open sourced and has not worked on it for a long time), which is handling with the gdi images, but it could not save the new images. And because i'm a beginner with Gdi/+ i leaved it on hold.

But solving the problems in your code, solved the problems in my  project. :) 

Edited by Dan_555

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

Share this post


Link to post
Share on other sites

Dan_555,
 I am very grateful for your advice. Actually,
 I wanted to know more about the routine that saves the image loaded in the Pucture control rather than the capture storage code. 
Thank you again.

Share this post


Link to post
Share on other sites
Posted (edited)

Yes, i'm seeking for a way to save (or to access) it, but no success atm.

This is the best i came with, (skipped few of the temporary files).

I'v tried to rotate the whichever picture is in the $Pic Control, (if you uncomment the RotateCtrl($pic) from the Case $Slider) but it looks like the control does not return the handle to the picture (at least this is how i understand it).

Moreover, if you uncomment it, the Rotate S.Capt button does not do, what it should. 

The Save Pic  button causes the _GDIPlus_ImageSaveToFile to return @error #10 and extendend 2

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=0.0.0.82
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <SendMessage.au3>
#include <ScreenCapture.au3>
#include <Constants.au3>
#include <Array.au3>
;Opt("MustDeclareVars", 1)

;Global $hBitmap, $hImage, $hImage_new, $sCLSID, $tData, $tParams

Global $Form = GUICreate("Picture Test", 500, 320)

Local $labpic = GUICtrlCreateLabel("", 9, 9, 302, 302, $SS_BLACKFRAME)
GUICtrlSetState(-1, $GUI_DISABLE)

Global $Pic = GUICtrlCreatePic("", 10, 10, 300, 300)

Local $btnCapture = GUICtrlCreateButton("screen capture", 320, 10, 80, 30)
GUICtrlSetTip (-1,"Capture a screenshot")
Local $btnRotateCapure = GUICtrlCreateButton("Rotate S.Capt.", 320, 45, 80, 30)
GUICtrlSetTip (-1,"Capture a screenshot, then rotate it." & @CRLF & "Set the slider for the rotation.")
Local $btnLoadImage = GUICtrlCreateButton("Load image", 405, 10, 80, 30)
GUICtrlSetTip (-1,"Choose an image to Load")
Local $btnRotateImage = GUICtrlCreateButton("Rotate image", 405, 45, 80, 30)
GUICtrlSetTip (-1,"Choose, Load an image, then rotate it." & @CRLF & "Set the slider for the rotation.")
$Slider1 = GUICtrlCreateSlider(318, 104, 150, 45, BitOR($GUI_SS_DEFAULT_SLIDER,$TBS_FIXEDLENGTH))
GUICtrlSetLimit(-1, 7, 0)
$SliderNr = GUICtrlCreateLabel("", 472, 108, 10, 17)
$ButtonSave = GUICtrlCreateButton("Save Pic", 316, 290, 72, 21)

GUISetState(@SW_SHOW)

Global $rota=GUICtrlRead($Slider1)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $btnCapture ;When clicking on the screen capture button

            Screen_Capture() ; Execute screen capture function

        Case $btnLoadImage ;if you click the Load Image button

            Load_Image(FileOpenDialog("Please Chose an image file",@WorkingDir,"Image (Jpg;*.jpg;Png;*.png)",1)) ; Execute image load function

        Case $btnRotateImage ;if you click the rotate image button
            local $tmpfilen=FileOpenDialog("Please Chose an image file",@WorkingDir,"Image (Jpg;*.jpg;Png;*.png)",1)
                Rotate_Image($tmpfilen, $rota) ; Execute image rotation function
        Case $btnRotateCapure
                Rotate_SCap($rota) ; Execute image rotation function
        Case $Slider1
            $rota=GUICtrlRead($Slider1)
            GUICtrlSetData($SliderNr,$rota)
            RotateCTRL($Pic)
        Case $ButtonSave
            SavePic($Pic)
    EndSwitch
WEnd

local $tmpfilen=@TempDir & "\rotate.jpg"
If FileExists($tmpfilen) then FileDelete($tmpfilen)
GUIDelete($Form)

Func RotateCTRL($id,$x=1)
    _GDIPlus_Startup()
    $hBitmap2 = _SendMessage(ControlGetHandle($Form, "", $id), $BM_GETIMAGE, 0, 0)
    CW($hBitmap2)
    $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)
    $hImage = _GDIPlus_ImageResize($hImage2, 300, 300)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageRotateFlip($hBitmap, $x)

    _SetBitmapToCtrl($Pic, $hBitmap)

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hBitmap)
    _GDIPlus_ImageDispose($hBitmap2)
      _WinAPI_DeleteObject($hBitmap2)
    _GDIPlus_Shutdown()
EndFunc

Func SavePic($id,$fname="r:\Test.jpg")
    Local $hHBITMAP,$hImage
    _GDIPlus_Startup()
    $hHBITMAP = _SendMessage(ControlGetHandle($Form, "", $id), $BM_GETIMAGE, 0, 0)
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP)
    ConsoleWrite($fname & @CRLF)
    if _GDIPlus_ImageSaveToFile($hImage, $fname ) = False Then
        Local $er = @error
        Local $ex = @extended
        cw("ImageSaveError " & $er & " / " & $ex)
    EndIf
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_Shutdown()
EndFunc

; ============================================
Func Screen_Capture()

    _GDIPlus_Startup()
    $hBitmap2 = _ScreenCapture_Capture("", 100, 100, 300, 300, False) ; 200 x 200
    ;$hBitmap2 = _ScreenCapture_Capture("", 100, 100, 400, 400,True) ; 200 x 200
    $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)
    $hImage = _GDIPlus_ImageResize($hImage2, 300, 300) ; resize to 300 x 300
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

    _SetBitmapToCtrl($Pic, $hBitmap)

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage2)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteObject($hBitmap2)
    _GDIPlus_Shutdown()

EndFunc   ;==>Screen_Capture

Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $SS_IMAGE_BITMAP = 0

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)

    _SendMessage($hWnd, $STM_SETIMAGE, $SS_IMAGE_BITMAP, $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    Return 1

EndFunc   ;==>_SetBitmapToCtrl

;==========================================================================================================================================================
;func Load_Image()

;  _GDIPlus_Startup() ; Initialize GDI+ library
; $hOrigSS = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\1.jpg")     ; Capture 32 bit bitmap and return a bitmap image object
; $hClip = _GDIPlus_BitmapCloneArea($hOrigSS,  0, 0, 300, 300) ; Clip out area of bitmap object; left,top,width,height
; $hResize = _GDIPlus_ImageScale($hClip,1,1) ; Enlarge width & height
;$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hOrigSS) ; Create bitmap object from bitmap handle

; $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic)) ; Get the winhandle of the control holding the image and create Graphics Object
; _GDIPlus_GraphicsDrawImage($hGraphic, $hResize,0,0) ; Paste the picture into the control holding the image

; _GDIPlus_GraphicsDispose($hGraphic) ; Clean up resources
;_GDIPlus_BitmapDispose($hBitmap)
; _WinAPI_DeleteObject($hOrigSS)
; _GDIPlus_Shutdown() ; Shut down GDI+ library
;EndFunc
;=======================================================================================================================================================

Func Load_Image($FileName = @TempDir & "\rotate.jpg") ; Load the image to fit the picture control size.

    _GDIPlus_Startup()
    ;$g_hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\05_PictureBox1_ex.jpg")
    If FileExists($FileName) = 0 Then
        $hBitmap2 = _ScreenCapture_Capture($FileName, 100, 100, 300, 300, False)
        _WinAPI_DeleteObject($hBitmap2)
    EndIf
    $g_hImage = _GDIPlus_ImageLoadFromFile($FileName)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic))
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $g_hImage, 0, 0, 300, 300)
    _GDIPlus_ImageDispose($g_hImage)                                        ;<------- adition
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($g_hImage)
    _GDIPlus_Shutdown()

EndFunc   ;==>Load_Image

Func Rotate_SCap($flagFilp = 2)
        ;$flagfilp = 1 rotates 90 degrees, 2 rotates 180 degrees, 3 rotates 270 degrees
    _GDIPlus_Startup()
    $hBitmap2 = _ScreenCapture_Capture("", 100, 100, 300, 300, False)
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)
    $hImage_new = _GDIPlus_ImageResize($hImage, 600, 600) ;resize image
    _GDIPlus_ImageRotateFlip($hImage_new, $flagFilp)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic))
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage_new, 0, 0, 300, 300)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage_new)
    _WinAPI_DeleteObject($hBitmap2)
    _GDIPlus_Shutdown()
EndFunc

Func Rotate_Image($FileName2 = @TempDir & "\rotate.jpg", $flagFilp = 2)
    ;$flagfilp = 1 rotates 90 degrees, 2 rotates 180 degrees, 3 rotates 270 degrees

    _GDIPlus_Startup()
    If FileExists($FileName2) = 0 Then
        $hBitmap2 = _ScreenCapture_Capture($FileName2, 100, 100, 300, 300, False)
        _WinAPI_DeleteObject($hBitmap2)
    EndIf

    $hImage = _GDIPlus_ImageLoadFromFile($FileName2)
    $hImage_new = _GDIPlus_ImageResize($hImage, 600, 600) ;resize image
    _GDIPlus_ImageRotateFlip($hImage_new, $flagFilp)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic))
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage_new, 0, 0, 300, 300)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage_new)
    _GDIPlus_Shutdown()
EndFunc   ;==>Rotate_Image

Func cw($txt)
    ConsoleWrite($txt & @CRLF)
EndFunc   ;==>cw

I have read some of the posts, and they suggest something: to keep an handle of a image, which is set as the picture.

But i hope someone knows how to extract the picture, if it is set up, just like now.

 

Edited by Dan_555

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

Share this post


Link to post
Share on other sites
Posted (edited)

Ok, at least i'v found a solution to save the image from the $pic control, thanks to UEZ.

Replace the whole save pic function with following code:

Func SavePic($id,$fname=@Tempdir & "\Test.jpg")
    Local $hHBITMAP,$hImage
    _GDIPlus_Startup()
    $pic_hWnd = ControlGetHandle($Form,"",$id)
    $pic_hdc = _WinAPI_GetDC($pic_hWnd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($pic_hdc)

    ;$hHBITMAP = _SendMessage(ControlGetHandle($Form, "", $id), $BM_GETIMAGE, 0, 0, 1)
    ;CW($hHBITMAP)
    ;$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP)
    ConsoleWrite($hImage & @CRLF)
    _GDIPlus_Save_to_Image($fname, $Form )
    if @error >0 Then
        Local $er = @error
        Local $ex = @extended
        cw("ImageSaveError " & $er & " / " & $ex)
    EndIf

    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DeleteObject($hHBitmap)

    _GDIPlus_Shutdown()
EndFunc


; #FUNCTION# =============================================================================
; Name.............:        _GDIPlus_Save_to_Image
; Description ...:      INTERNAL FUNCTION - save drawnelements in GUI to file
; Syntax...........:        _GDIPlus_Save_to_Image($file, $hWnd)
; Parameters ...:       $file - filename
;                               $hWnd - handle to GUI
; Author .........:         ptrex, ProgAndy, UEZ
; =========================================================================================
Func _GDIPlus_Save_to_Image($file, $hWnd)
    Local $hDC, $memBmp, $memDC, $hImage, $w, $h, $size, $err, $sCLSID, $ext, $fExt
    If $file <> "" Or $hWnd <> "" Then
        $size = WinGetClientSize($hWnd)
        $w = $size[0]
        $h = $size[1]
        $hDC = _WinAPI_GetDC($hWnd)
        $memDC = _WinAPI_CreateCompatibleDC($hDC)
        $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
        _WinAPI_SelectObject ($memDC, $memBmp)
        _WinAPI_BitBlt($memDC, 0, 0, $w, $h, $hDC, 0, 0, 0x00CC0020) ;  0x00CC0020 = $SRCCOPY
        $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp)
        $ext = "png,bmp,jpg,tif,gif"
        $fExt = StringRight($file, 3)
        If Not StringInStr($ext, $fExt)  Then
            $CLSID = "PNG"
            $file &= ".png"
        Else
            $CLSID = $fExt
        EndIf
        $sCLSID = _GDIPlus_EncodersGetCLSID ($CLSID)
        If Not _GDIPlus_ImageSaveToFileEx ($hImage, $file, $sCLSID) Then $err = 1
        _GDIPlus_ImageDispose ($hImage)
        _WinAPI_ReleaseDC($hWnd, $hDC)
        _WinAPI_DeleteDC($memDC)
        _WinAPI_DeleteObject ($memBmp)
        If $err Then Return SetError(2, 0, 0)
        Return SetError(0, 0, 0)
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc

 

Edited by Dan_555

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

Share this post


Link to post
Share on other sites

Dan_555, the code you created and found is really great. This was the code I wanted. 
However, when I put the code you wrote in my code, the result was to save the entire form, not just the Picture control. 
I want to save only the images loaded in the Picture control. 
However, you are respected for extending the scope to this point.

Share this post


Link to post
Share on other sites
Posted (edited)
Quote

However, when I put the code you wrote in my code, the result was to save the entire form, not just the Picture control. 

I must have missed that bit, anyway there is a workaround, well it is not 100%:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=0.0.0.82
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <SendMessage.au3>
#include <ScreenCapture.au3>
#include <Constants.au3>
#include <Array.au3>
;Opt("MustDeclareVars", 1)

;Global $hBitmap, $hImage, $hImage_new, $sCLSID, $tData, $tParams

Global $Form = GUICreate("Picture Test", 500, 320)

Local $labpic = GUICtrlCreateLabel("", 9, 9, 302, 302, $SS_BLACKFRAME)
GUICtrlSetState(-1, $GUI_DISABLE)

Global $Pic = GUICtrlCreatePic("", 10, 10, 300, 300)

Local $btnCapture = GUICtrlCreateButton("screen capture", 320, 10, 80, 30)
GUICtrlSetTip (-1,"Capture a screenshot")
Local $btnRotateCapure = GUICtrlCreateButton("Rotate S.Capt.", 320, 45, 80, 30)
GUICtrlSetTip (-1,"Capture a screenshot, then rotate it." & @CRLF & "Set the slider for the rotation.")
Local $btnLoadImage = GUICtrlCreateButton("Load image", 405, 10, 80, 30)
GUICtrlSetTip (-1,"Choose an image to Load")
Local $btnRotateImage = GUICtrlCreateButton("Rotate image", 405, 45, 80, 30)
GUICtrlSetTip (-1,"Choose, Load an image, then rotate it." & @CRLF & "Set the slider for the rotation.")
$Slider1 = GUICtrlCreateSlider(318, 104, 150, 45, BitOR($GUI_SS_DEFAULT_SLIDER,$TBS_FIXEDLENGTH))
GUICtrlSetLimit(-1, 7, 0)
$SliderNr = GUICtrlCreateLabel("", 472, 108, 10, 17)
$ButtonSave = GUICtrlCreateButton("Save Pic", 316, 290, 72, 21)

GUISetState(@SW_SHOW)

Global $rota=GUICtrlRead($Slider1)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $btnCapture ;When clicking on the screen capture button

            Screen_Capture() ; Execute screen capture function

        Case $btnLoadImage ;if you click the Load Image button

            Load_Image(FileOpenDialog("Please Chose an image file",@WorkingDir,"Image (Jpg;*.jpg;Png;*.png)",1)) ; Execute image load function

        Case $btnRotateImage ;if you click the rotate image button
            local $tmpfilen=FileOpenDialog("Please Chose an image file",@WorkingDir,"Image (Jpg;*.jpg;Png;*.png)",1)
                Rotate_Image($tmpfilen, $rota) ; Execute image rotation function
        Case $btnRotateCapure
                Rotate_SCap($rota) ; Execute image rotation function
        Case $Slider1
            $rota=GUICtrlRead($Slider1)
            GUICtrlSetData($SliderNr,$rota)
            ;RotateCTRL($Pic)
        Case $ButtonSave
            SavePic($Pic)
    EndSwitch
WEnd

local $tmpfilen=@TempDir & "\rotate.png"
If FileExists($tmpfilen) then FileDelete($tmpfilen)
GUIDelete($Form)

Func RotateCTRL($id,$x=1)
    _GDIPlus_Startup()
    $hBitmap2 = _SendMessage(ControlGetHandle($Form, "", $id), $BM_GETIMAGE, 0, 0, 0)
    CW($hBitmap2)
    $hImage2 =  _GDIPlus_GraphicsCreateFromHWND($hBitmap2)
    $hImage = _GDIPlus_ImageResize($hImage2, 300, 300)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageRotateFlip($hBitmap, $x)

    _SetBitmapToCtrl($Pic, $hBitmap)

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hBitmap)
    _GDIPlus_ImageDispose($hBitmap2)
      _WinAPI_DeleteObject($hBitmap2)
    _GDIPlus_Shutdown()
EndFunc

Func SavePic($id,$fname="r:\Test.png")
    Local $hHBITMAP,$hImage
    _GDIPlus_Startup()
    $pic_hWnd = ControlGetHandle($Form,"",$id)
    $pic_hdc = _WinAPI_GetDC($pic_hWnd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($pic_hdc)

    ;$hHBITMAP = _SendMessage(ControlGetHandle($Form, "", $id), $BM_GETIMAGE, 0, 0, 1)
    ;CW($hHBITMAP)
    ;$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP)
    ConsoleWrite($hImage & @CRLF)
    _GDIPlus_Save_to_Image($fname, $Form, $id )
    ;controlscreenshot_to_Image($fname, $Form, $id )
    if @error >0 Then
        Local $er = @error
        Local $ex = @extended
        cw("ImageSaveError " & $er & " / " & $ex)
    EndIf

    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DeleteObject($hHBitmap)

    _GDIPlus_Shutdown()
EndFunc
; ============================================
Func Screen_Capture()

    _GDIPlus_Startup()
    $hBitmap2 = _ScreenCapture_Capture("", 100, 100, 300, 300, False) ; 200 x 200
    ;$hBitmap2 = _ScreenCapture_Capture("", 100, 100, 400, 400,True) ; 200 x 200
    $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)
    $hImage = _GDIPlus_ImageResize($hImage2, 300, 300) ; resize to 300 x 300
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

    _SetBitmapToCtrl($Pic, $hBitmap)

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage2)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteObject($hBitmap2)
    _GDIPlus_Shutdown()

EndFunc   ;==>Screen_Capture

Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $SS_IMAGE_BITMAP = 0

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)

    _SendMessage($hWnd, $STM_SETIMAGE, $SS_IMAGE_BITMAP, $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    Return 1

EndFunc   ;==>_SetBitmapToCtrl

;==========================================================================================================================================================
;func Load_Image()

;  _GDIPlus_Startup() ; Initialize GDI+ library
; $hOrigSS = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\1.jpg")     ; Capture 32 bit bitmap and return a bitmap image object
; $hClip = _GDIPlus_BitmapCloneArea($hOrigSS,  0, 0, 300, 300) ; Clip out area of bitmap object; left,top,width,height
; $hResize = _GDIPlus_ImageScale($hClip,1,1) ; Enlarge width & height
;$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hOrigSS) ; Create bitmap object from bitmap handle

; $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic)) ; Get the winhandle of the control holding the image and create Graphics Object
; _GDIPlus_GraphicsDrawImage($hGraphic, $hResize,0,0) ; Paste the picture into the control holding the image

; _GDIPlus_GraphicsDispose($hGraphic) ; Clean up resources
;_GDIPlus_BitmapDispose($hBitmap)
; _WinAPI_DeleteObject($hOrigSS)
; _GDIPlus_Shutdown() ; Shut down GDI+ library
;EndFunc
;=======================================================================================================================================================

Func Load_Image($FileName = @TempDir & "\rotate.png") ; Load the image to fit the picture control size.

    _GDIPlus_Startup()
    ;$g_hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\05_PictureBox1_ex.jpg")
    If FileExists($FileName) = 0 Then
        $hBitmap2 = _ScreenCapture_Capture($FileName, 100, 100, 300, 300, False)
        _WinAPI_DeleteObject($hBitmap2)
    EndIf
    $g_hImage = _GDIPlus_ImageLoadFromFile($FileName)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic))
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $g_hImage, 0, 0, 300, 300)
    _GDIPlus_ImageDispose($g_hImage)                                        ;<------- adition
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($g_hImage)
    _GDIPlus_Shutdown()

EndFunc   ;==>Load_Image

Func Rotate_SCap($flagFilp = 2)
        ;$flagfilp = 1 rotates 90 degrees, 2 rotates 180 degrees, 3 rotates 270 degrees
    _GDIPlus_Startup()
    $hBitmap2 = _ScreenCapture_Capture("", 100, 100, 300, 300, False)
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)
    $hImage_new = _GDIPlus_ImageResize($hImage, 600, 600) ;resize image
    _GDIPlus_ImageRotateFlip($hImage_new, $flagFilp)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic))
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage_new, 0, 0, 300, 300)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage_new)
    _WinAPI_DeleteObject($hBitmap2)
    _GDIPlus_Shutdown()
EndFunc

Func Rotate_Image($FileName2 = @TempDir & "\rotate.png", $flagFilp = 2)
    ;$flagfilp = 1 rotates 90 degrees, 2 rotates 180 degrees, 3 rotates 270 degrees

    _GDIPlus_Startup()
    If FileExists($FileName2) = 0 Then
        $hBitmap2 = _ScreenCapture_Capture($FileName2, 100, 100, 300, 300, False)
        _WinAPI_DeleteObject($hBitmap2)
    EndIf

    $hImage = _GDIPlus_ImageLoadFromFile($FileName2)
    $hImage_new = _GDIPlus_ImageResize($hImage, 600, 600) ;resize image
    _GDIPlus_ImageRotateFlip($hImage_new, $flagFilp)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic))
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage_new, 0, 0, 300, 300)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage_new)
    _GDIPlus_Shutdown()
EndFunc   ;==>Rotate_Image

Func cw($txt)
    ConsoleWrite($txt & @CRLF)
EndFunc   ;==>cw

; #FUNCTION# =============================================================================
; Name.............:        _GDIPlus_Save_to_Image
; Description ...:      INTERNAL FUNCTION - save drawnelements in GUI to file
; Syntax...........:        _GDIPlus_Save_to_Image($file, $hWnd)
; Parameters ...:       $file - filename
;                               $hWnd - handle to GUI
; Author .........:         ptrex, ProgAndy, UEZ
; =========================================================================================
Func _GDIPlus_Save_to_Image($file, $hWnd,$id)
    Local $hDC, $memBmp, $memDC, $hImage, $w, $h, $x, $y, $z , $size, $err, $sCLSID, $ext, $fExt
    $z=20
    If $file <> "" Or $hWnd <> "" Then
        $size = ControlGetPos($hWnd,"",$id)

        $x= $size[0]-$z
        $y= $size[1]-$z
        $w =$size[2]
        $h =$size[3]

        $hDC = _WinAPI_GetDC($hWnd)
        $memDC = _WinAPI_CreateCompatibleDC($hDC)
        $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
        _WinAPI_SelectObject ($memDC, $memBmp)
        _WinAPI_BitBlt($memDC, $x, $y, $w+$z, $h+$z, $hDC, 0, 0, 0x00CC0020) ;  0x00CC0020 = $SRCCOPY
        $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp)
        $ext = "png,bmp,jpg,tif,gif"
        $fExt = StringRight($file, 3)
        If Not StringInStr($ext, $fExt)  Then
            $CLSID = "PNG"
            $file &= ".png"
        Else
            $CLSID = $fExt
        EndIf
        $sCLSID = _GDIPlus_EncodersGetCLSID ($CLSID)
        If Not _GDIPlus_ImageSaveToFileEx ($hImage, $file, $sCLSID) Then $err = 1
        _GDIPlus_ImageDispose ($hImage)
        _WinAPI_ReleaseDC($hWnd, $hDC)
        _WinAPI_DeleteDC($memDC)
        _WinAPI_DeleteObject ($memBmp)
        If $err Then Return SetError(2, 0, 0)
        Return SetError(0, 0, 0)
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc

Func controlscreenshot_to_Image($file,$hWnd,$id)
        Local $coords
        $Coords=GetControlScreenCoord($hwnd,$id)

        _ScreenCapture_Capture($file, $coords[0], $coords[1], $coords[2], $coords[3], False)
        if @error Then
            CW("Screen Capture error: " & @error)
        EndIf
EndFunc

Func GetControlScreenCoord($hwnd,$id)
;code by /dev/null  : https://www.autoitscript.com/forum/topic/40753-get-window-coordinates-of-a-pic-control/
local $handle,$lpRect, $ret
$handle = ControlGetHandle($hwnd, "", $id)

If @error Then
    MsgBox(0,"ERROR","No Handle found")
    Exit
EndIf

$lpRect = DllStructCreate("int;int;int;int")
$ret = DllCall("user32.dll","int","GetWindowRect","hwnd",$handle,"ptr",DllStructGetPtr($lpRect))

If @error Then
    MsgBox(0,"","DllCall error")
    Exit
EndIf

Dim $coords[4]

$coords[0] = DllStructGetData($lpRect,1)
$coords[1] = DllStructGetData($lpRect,2)
$coords[2] = DllStructGetData($lpRect,3)
$coords[3] = DllStructGetData($lpRect,4)
$lpRect=""
$ret=""
Return $coords
EndFunc

In the _GDIPlus_Save_to_Image, i had to use some arbitrary number for the $z variable, so it can capture the control only.

I suspect that this solution may not work on every windows correctly. (because of different theme settings/Different title height or whatever).

Therefore i had another idea, to use the screen capture on the pic control. This may work, as long as the pic control is fully visible.

 Comment  the 1st, and uncomment the second line

    _GDIPlus_Save_to_Image($fname, $Form, $id )
    ;controlscreenshot_to_Image($fname, $Form, $id )

in the SavePic function, to test it. 

Edited by Dan_555

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

Share this post


Link to post
Share on other sites

Dan_555, I put in the code you gave me and I got the result I wanted. 

The way you use your own slide controls is creative. But I was curious. 

I am wondering if it is possible to implement a function that shows the loaded image in its original size. 

To do this, you'll have to remember and show the path after the image is loaded, but I'm wondering how to implement it. 

Anyway, the method you showed me is very helpful for me. Thank you^^

Share this post


Link to post
Share on other sites
Posted (edited)

Hmm,

put this somewhere after include statements:

Global $loadedimg=""

then, in the loadimage function add, after the     $g_hImage = _GDIPlus_ImageLoadFromFile($FileName) :

$loadedimg=$FileName

and you should have the path+filename of the loaded image.

Replace the $btnRotateImage case with:

Case $btnRotateImage ;if you click the rotate image button
            Local $tmpfilen = $loadedimg
            Rotate_Image($tmpfilen, $rota)     ; Execute image rotation function

And  the $Slider1 with:

Case $Slider1
            $rota = GUICtrlRead($Slider1)
            GUICtrlSetData($SliderNr, $rota)
            Rotate_Image($loadedimg, $rota)

Now, the slider is automatically loading and rotating the last loaded image.

An example of how to display images can be found here: https://www.autoitscript.com/forum/topic/200086-display-png-images/?tab=comments#comment-1435398

Edited by Dan_555

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

Share this post


Link to post
Share on other sites
Posted (edited)

Dan_555, 

I tried it the way you told me and it works fine. 

However, by writing a routine that shows the actual size and saves it again, the image is broken and saved. 

This is the full source code I wrote. Please test it once.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=0.0.0.149
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <SendMessage.au3>
#include <ScreenCapture.au3>
#include <Constants.au3>

;Opt("MustDeclareVars", 1)

;Global $hBitmap, $hImage, $hImage_new, $sCLSID, $tData, $tParams

Local $Form = GUICreate("Picture Test", 500, 500)

local $labpic = GUICtrlCreateLabel("",9,9,302,302,$SS_BLACKFRAME)
GUICtrlSetState(-1, $GUI_DISABLE)

Local $Pic = GUICtrlCreatePic("", 10, 10, 300, 300)

Local $btnCapture = GUICtrlCreateButton("스크린 캡쳐",320,10,80,30)

local $btnLoadImage = GUICtrlCreateButton("이미지 로드",405,10,80,30)

local $btnRotateImage = GUICtrlCreateButton("이미지 회전",320,45,80,30)

Local $btnSaveImage = GUICtrlCreateButton("이미지 저장", 405,45,80,30)

Local $btnRealSize = GUICtrlCreateButton("실제 사이즈", 320,80,80,30)

GUISetState(@SW_SHOW)


While 1

  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      ExitLoop

      Case $btnCapture ;스크린 캡쳐 버튼 클릭할 경우

          Screen_Capture();스크린 캡쳐 함수 실행

      case $btnLoadImage ;이미지 로드 버튼을 클릭한 경우

          Load_Image(); 이미지 로드 함수 실행

      case $btnRotateImage ;이미지회전 버튼을 클릭한 경우

          For $X = 0 To 9
            Rotate_Image(@ScriptDir & "\05_PictureBox1_ex.jpg", $X) ; 이미지 회전 함수 실행
            Sleep(250)
          Next

      case $btnSaveImage ;이미지 저장 버튼을 클릭한 경우

           SavePic($pic)

      case $btnRealSize ;실제 사이즈 버튼을 클릭한 경우

           RealSize_image(@ScriptDir & "\05_PictureBox1_ex.jpg")

  EndSwitch
WEnd

GUIDelete($Form)

; ============================================
Func Screen_Capture()

 _GDIPlus_Startup()
 $hBitmap2 = _ScreenCapture_Capture("", 100, 100, 300, 300, False) ; 200 x 200
 ;$hBitmap2 = _ScreenCapture_Capture("", 100, 100, 400, 400,True) ; 200 x 200
 $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)
 $hImage = _GDIPlus_ImageResize($hImage2, 300, 300) ; resize to 300 x 300
 $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

 _SetBitmapToCtrl($Pic, $hBitmap)

 ;Clean up and shutdown GDIPlus.
 _GDIPlus_ImageDispose($hImage)
 _GDIPlus_ImageDispose($hImage2)
 _WinAPI_DeleteObject($hBitmap)
 _WinAPI_DeleteObject($hBitmap2)
 _GDIPlus_Shutdown()

EndFunc

Func _SetBitmapToCtrl($CtrlId, $hBitmap)
  Local Const $SS_IMAGE_BITMAP = 0

  Local $hWnd = GUICtrlGetHandle($CtrlId)
  If $hWnd = 0 Then Return SetError(1, 0, 0)

  _SendMessage($hWnd, $STM_SETIMAGE, $SS_IMAGE_BITMAP, $hBitmap)
  If @error Then Return SetError(4, 0, 0)
  Return 1

EndFunc   ;==>_SetBitmapToCtrl

;==========================================================================================================================================================
;func Load_Image()

  ;  _GDIPlus_Startup() ; Initialize GDI+ library
  ; $hOrigSS = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\1.jpg")     ; Capture 32 bit bitmap and return a bitmap image object
  ; $hClip = _GDIPlus_BitmapCloneArea($hOrigSS,  0, 0, 300, 300) ; Clip out area of bitmap object; left,top,width,height
  ; $hResize = _GDIPlus_ImageScale($hClip,1,1) ; Enlarge width & height
   ;$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hOrigSS) ; Create bitmap object from bitmap handle

  ; $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic)) ; Get the winhandle of the control holding the image and create Graphics Object
  ; _GDIPlus_GraphicsDrawImage($hGraphic, $hResize,0,0) ; Paste the picture into the control holding the image

  ; _GDIPlus_GraphicsDispose($hGraphic) ; Clean up resources
   ;_GDIPlus_BitmapDispose($hBitmap)
  ; _WinAPI_DeleteObject($hOrigSS)
  ; _GDIPlus_Shutdown() ; Shut down GDI+ library
;EndFunc
;=======================================================================================================================================================

Func Load_Image($FileName = @ScriptDir & "\05_PictureBox1_ex.jpg") ;해당이미지를 Picture 컨트롤 사이즈에 맞혀 로드한다.

  _GDIPlus_Startup()
  ;$g_hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\05_PictureBox1_ex.jpg")
   $g_hImage = _GDIPlus_ImageLoadFromFile($FileName)
   $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($Pic))
  _GDIPlus_GraphicsDrawImageRect($hGraphic, $g_hImage, 0, 0, 300, 300)
  _GDIPlus_ImageDispose($g_hImage)
  _GDIPlus_GraphicsDispose($hGraphic)
  _WinAPI_DeleteObject($g_hImage)
  _GDIPlus_Shutdown()

EndFunc ;==>Load_Image

Func Rotate_Image($FileName2 = @ScriptDir & "\05_PictureBox1_ex.jpg", $flagFilp = 2)
    ;$flagfilp = 1 rotates 90 degrees, 2 rotates 180 degrees, 3 rotates 270 degrees

    _GDIPlus_Startup()

    $hImage = _GDIPlus_ImageLoadFromFile($FileName2) ;해당 이미지파일을 변수에 저장하는 함수
    $hImage_new = _GDIPlus_ImageResize($hImage, 600, 600) ;이미지 사이즈를 조정하는 함수
    _GDIPlus_ImageRotateFlip($hImage_new, $flagFilp) ;이미지 회전을 돌리는 함수

;~  Local $hGUI = GUICreate("GDI+ test", 800, 600, -1, -1) ;create a test gui to display the rotated image
;~  GUISetState(@SW_SHOW)

;~  Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
;~  _GDIPlus_GraphicsDrawImage($hGraphics, $hImage_new, 0, 0) ;display rotated image
;~  While GUIGetMsg() <> $GUI_EVENT_CLOSE
;~  WEnd
;~  GUIDelete($hGUI)

    $ftemp = @TempDir & "\rotate" & $flagFilp & ".jpg"
    If FileExists($ftemp) Then
        If FileDelete($ftemp) = 0 Then cw("could not delete")
    EndIf
    If _GDIPlus_ImageSaveToFile($hImage_new, $ftemp) = False Then
        Local $er = @error
        Local $ex = @extended
        cw("ImageSaveError " & $er & " / " & $ex & " $flag= " & $flagFilp)
    EndIf

    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage_new)
    _GDIPlus_Shutdown()

    Load_Image($ftemp)

EndFunc   ;==>Rotate_Image

Func cw($txt)
    ConsoleWrite($txt & @CRLF)
EndFunc   ;==>cw


Func SavePic($id,$idForm = $Form,$fname=@DesktopDir & "\Test.png")
    Local $hHBITMAP,$hImage
    _GDIPlus_Startup()
    $pic_hWnd = ControlGetHandle($idForm,"",$id)
    $pic_hdc = _WinAPI_GetDC($pic_hWnd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($pic_hdc)

    ;$hHBITMAP = _SendMessage(ControlGetHandle($Form, "", $id), $BM_GETIMAGE, 0, 0, 1)
    ;CW($hHBITMAP)
    ;$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP)
    ConsoleWrite($hImage & @CRLF)
    _GDIPlus_Save_to_Image($fname, $idForm, $id )
    ;controlscreenshot_to_Image($fname, $Form, $id )
    if @error >0 Then
        Local $er = @error
        Local $ex = @extended
        cw("ImageSaveError " & $er & " / " & $ex)
    EndIf

    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DeleteObject($hHBitmap)

    _GDIPlus_Shutdown()
EndFunc


; #FUNCTION# =============================================================================
; Name.............:        _GDIPlus_Save_to_Image
; Description ...:      INTERNAL FUNCTION - save drawnelements in GUI to file
; Syntax...........:        _GDIPlus_Save_to_Image($file, $hWnd)
; Parameters ...:       $file - filename
;                               $hWnd - handle to GUI
; Author .........:         ptrex, ProgAndy, UEZ
; =========================================================================================
Func _GDIPlus_Save_to_Image($file, $hWnd,$id)
    Local $hDC, $memBmp, $memDC, $hImage, $w, $h, $x, $y, $z , $size, $err, $sCLSID, $ext, $fExt
    $z=20
    If $file <> "" Or $hWnd <> "" Then
        $size = ControlGetPos($hWnd,"",$id)

        $x= $size[0]-$z
        $y= $size[1]-$z
        $w =$size[2]
        $h =$size[3]

        $hDC = _WinAPI_GetDC($hWnd)
        $memDC = _WinAPI_CreateCompatibleDC($hDC)
        $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
        _WinAPI_SelectObject ($memDC, $memBmp)
        _WinAPI_BitBlt($memDC, $x, $y, $w+$z, $h+$z, $hDC, 0, 0, 0x00CC0020) ;  0x00CC0020 = $SRCCOPY
        $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp)
        $ext = "png,bmp,jpg,tif,gif"
        $fExt = StringRight($file, 3)
        If Not StringInStr($ext, $fExt)  Then
            $CLSID = "PNG"
            $file &= ".png"
        Else
            $CLSID = $fExt
        EndIf
        $sCLSID = _GDIPlus_EncodersGetCLSID ($CLSID)
        If Not _GDIPlus_ImageSaveToFileEx ($hImage, $file, $sCLSID) Then $err = 1
        _GDIPlus_ImageDispose ($hImage)
        _WinAPI_ReleaseDC($hWnd, $hDC)
        _WinAPI_DeleteDC($memDC)
        _WinAPI_DeleteObject ($memBmp)
        If $err Then Return SetError(2, 0, 0)
        Return SetError(0, 0, 0)
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc


func RealSize_image($sFileName) ;이미지를 실제 사이즈로 보여주는 함수

    ;$sFileName = @ScriptDir & "\display_image2.jpg"
If Not FileExists($sFileName) Then _
    Exit MsgBox($MB_TOPMOST, "Error", $sFileName & " not found")

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($sFileName)
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

$hGUI = GUICreate("Display Image in picture control", $iX, $iY+80, -1, -1, _
    -1, $WS_EX_TOPMOST)
$idPic = GUICtrlCreatePic("", 0, 0, $iX, $iY)
$btnRealSave = GUICtrlCreateButton("이미지 저장",40,$iY+20,80,30)

GUICtrlSendMsg($idPic, 0x0172, 0, $hBitmap) ; STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
            _WinAPI_DeleteObject($hBitmap)
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_Shutdown()
            ExitLoop

        Case $idPic
            MsgBox($MB_TOPMOST, "Information", "image was clicked")

        case $btnRealSave ;이미지 저장 버튼을 클릭한 경우

            SavePic($idPic,$hGUI,@DesktopDir & "\RealSize.png") ;저장 함수 실행


    EndSwitch
WEnd

EndFunc

 

 

Edited by halbum2040

Share this post


Link to post
Share on other sites
Posted (edited)

Atm i'm busy with other things, so i'll look, maybe saturday or sunday for the sollution, if there is any.

You said,

Quote

However, by writing a routine that shows the actual size and saves it again, the image is broken and saved. 

but i said, in a previous post:

Quote

In the _GDIPlus_Save_to_Image, i had to use some arbitrary number for the $z variable, so it can capture the control only.

You see, i had to manually adjust this variable, so that it captures the control.

And i said:

Quote

I suspect that this solution may not work on every windows correctly. (because of different theme settings/Different title height or whatever).

Which is, i guess, the case now.

The Original _GDIPlus_Save_to_Image function used:

$size = WinGetClientSize($hWnd)
        $w = $size[0]
        $h = $size[1]

To determine the size of the client window, and to save an image of the window.

In my next post, i had the idea to limit the capture to the pic control only, by getting the coordinates of it with 

$size = ControlGetPos($hWnd,"",$id)

but the returned position is not the correct one.  

you can see what it is capturing, If you set the $z to 0.

So i manually adjusted the $z to fit the $pic control, and added the $z calculation into 

 _WinAPI_BitBlt($memDC, $x, $y, $w+$z, $h+$z, $hDC, 0, 0, 0x00CC0020) ;  0x00CC0020 = $SRCCOPY

 but of course it does not work for other widows. 

 So, to get the real starting position of the control, the window title has to be, somehow, stripped out, and so to get the starting point of the Client area.

At least that is, what ill try when i have more time for debugging.

There is a post, which is talking about it, Here.

 

Edited by Dan_555

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

Share this post


Link to post
Share on other sites
Posted (edited)

Ok, now (i think) i understand where the error was.

it was the,

  _WinAPI_BitBlt($memDC, 0, 0, $w, $h, $hDC, 0, 0, 0x00CC0020) ;  0x00CC0020 = $SRCCOPY

which needed the correct parameters.

 

Here is the (hopefully) working function.

; #FUNCTION# =============================================================================
; Name.............:        _GDIPlus_Save_to_Image
; Description ...:      INTERNAL FUNCTION - save drawnelements in GUI to file
; Syntax...........:        _GDIPlus_Save_to_Image($file, $hWnd)
; Parameters ...:       $file - filename
;                               $hWnd - handle to GUI
; Author .........:         ptrex, ProgAndy, UEZ
; =========================================================================================
Func _GDIPlus_Save_to_Image($file, $hWnd,$id)
    Local $hDC, $memBmp, $memDC, $hImage, $w, $h, $x, $y, $z , $size, $err, $sCLSID, $ext, $fExt

    If $file <> "" Or $hWnd <> "" Then

        ;_ArrayDisplay($ClientPos, "Client position and size found")
        $size = ControlGetPos($hWnd,"",$id)

        $x= $size[0]
        $y= $size[1]
        $w =$size[2]
        $h =$size[3]

        $hDC = _WinAPI_GetDC($hWnd)
        $memDC = _WinAPI_CreateCompatibleDC($hDC)
        $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
        _WinAPI_SelectObject ($memDC, $memBmp)
        _WinAPI_BitBlt($memDC, 0, 0, $w, $h, $hDC, $x, $y, 0x00CC0020) ;  0x00CC0020 = $SRCCOPY
        $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp)
        $ext = "png,bmp,jpg,tif,gif"
        $fExt = StringRight($file, 3)
        If Not StringInStr($ext, $fExt)  Then
            $CLSID = "PNG"
            $file &= ".png"
        Else
            $CLSID = $fExt
        EndIf
        $sCLSID = _GDIPlus_EncodersGetCLSID ($CLSID)
        If Not _GDIPlus_ImageSaveToFileEx ($hImage, $file, $sCLSID) Then $err = 1
        _GDIPlus_ImageDispose ($hImage)
        _WinAPI_ReleaseDC($hWnd, $hDC)
        _WinAPI_DeleteDC($memDC)
        _WinAPI_DeleteObject ($memBmp)
        If $err Then Return SetError(2, 0, 0)
        Return SetError(0, 0, 0)
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc

 

Edited by Dan_555

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

Share this post


Link to post
Share on other sites

Dan_555, it's good to enter the code you provided. 

I know that you've been taking some time out of your busy schedule. 

Thank you for that. Really hard work. 

But I wanted to add another feature here. 

I wonder if it is possible to make the photo symmetrical or adjust the transparency with Auto-It. 

I know you're busy, but I'm sorry for taking another matter.

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...