Dan_555 Posted July 23, 2020 Posted July 23, 2020 (edited) Quote I wonder if it is possible to make the photo symmetrical Yes, just like this: expandcollapse popup#include <GDIPlus.au3> Local $iFname, $oFname, $tmptxt = "" $iFname = FileOpenDialog("Open a file", @ScriptDir, "All (*.*)") If StringRight(@ScriptDir, 1) <> "\" Then $tmptxt = "\" $oFname = @ScriptDir & $tmptxt & "test.png" _GDIPlus_BitmapAppendMirrorImage($iFname, $oFname) Func _GDIPlus_BitmapAppendMirrorImage($fname, $outFname) ;Modified code from https://www.autoitscript.com/forum/topic/183062-solved-looking-for-method-to-append-images-moved/ ;By Dan_555 _GDIPlus_Startup() Local $i, $aDim, $iW = 0, $iH = 0, $aImage1, $aImage2, $iY = 0 $aImage1 = _GDIPlus_ImageLoadFromFile($fname) $aDim = _GDIPlus_ImageGetDimension($aImage1) $iW = $aDim[0] $iH = $aDim[1] $aImage2 = _GDIPlus_ImageClone($aImage1) _GDIPlus_ImageRotateFlip($aImage2, 4) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW * 2, $iH), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) $aDim = _GDIPlus_ImageGetDimension($aImage1) _GDIPlus_GraphicsDrawImageRect($hGfx, $aImage1, 0, 0, $aDim[0], $aDim[1]) _GDIPlus_GraphicsDrawImageRect($hGfx, $aImage2, $aDim[0], 0, $aDim[0], $aDim[1]) _GDIPlus_ImageDispose($aImage1) _GDIPlus_ImageDispose($aImage2) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_ImageSaveToFile($hBitmap, $outFname) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() $aDim="" EndFunc ;==>_GDIPlus_BitmapAppendMirrorImage i had to modify the code from this post: Quote or adjust the transparency with Auto-It. I do not know how to do that atm. Edited July 23, 2020 by Dan_555 Some of my script sourcecode
halbum2040 Posted July 23, 2020 Author Posted July 23, 2020 Dan_555, the code you modified is really great. The method of simultaneously storing two images of the mirror image you selected is excellent. However, I would like to be able to save a single change image. For example, I want to know how to save the two images as test.png and the replaced image as test2.png.
Dan_555 Posted July 24, 2020 Posted July 24, 2020 (edited) Quote However, I would like to be able to save a single change image. I took few lines from my last post, and here it is, now saving single mirrored image: expandcollapse popup#include <GDIPlus.au3> Local $iFname, $oFname, $tmptxt = "" $iFname = FileOpenDialog("Open a file", @ScriptDir, "All (*.*)") If StringRight(@ScriptDir, 1) <> "\" Then $tmptxt = "\" $oFname = @ScriptDir & $tmptxt & "test.png" _GDIPlus_BitmapMirrorImage($iFname, $oFname) Func _GDIPlus_BitmapMirrorImage($fname, $outFname) ;Modified code from https://www.autoitscript.com/forum/topic/183062-solved-looking-for-method-to-append-images-moved/ ;By Dan_555 _GDIPlus_Startup() Local $i, $aDim, $iW = 0, $iH = 0, $aImage1, $iY = 0 $aImage1 = _GDIPlus_ImageLoadFromFile($fname) ;Load an image $aDim = _GDIPlus_ImageGetDimension($aImage1) ;Read the dimensions of the image and put it into the $aDim array $iW = $aDim[0] ;Width $iH = $aDim[1] ;Height _GDIPlus_ImageRotateFlip($aImage1, 4) ;Perform image rotation on the loaded image Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ;Create a buffer $hBitmap with the dimensions of the loaded image. Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsDrawImageRect($hGfx, $aImage1, 0, 0, $aDim[0], $aDim[1]) ;Draw the loaded image on the buffer _GDIPlus_ImageDispose($aImage1) ;Free the image _GDIPlus_GraphicsDispose($hGfx) ;Free graphic _GDIPlus_ImageSaveToFile($hBitmap, $outFname) ;Save the buffer _GDIPlus_ImageDispose($hBitmap) ;Free the bitmap _GDIPlus_Shutdown() $aDim="" EndFunc ;==>_GDIPlus_BitmapAppendMirrorImage Quote For example, I want to know how to save the two images as test.png and the replaced image as test2.png. I have no idea what you are trying to do, or why do you need that many copies of the pictures. But with the last 2 code samples, you have enough information to save whatever images you like to have. Edited July 24, 2020 by Dan_555 Some of my script sourcecode
halbum2040 Posted July 28, 2020 Author Posted July 28, 2020 Dan_555, how are you, I entered the code you provided and got a satisfactory result. I really appreciate it. But now I want to touch the part of the capture code. I am wondering if there is a way to capture the part corresponding to the picture control area. For example, if the form moves, the capture control moves as well, and I am wondering if I can only capture the stopped picture control part. Currently, my capture method is a method of capturing only selected parts. My code is below. 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
halbum2040 Posted July 28, 2020 Author Posted July 28, 2020 Oh, and the commenting in your code was very attentive. I was impressed.
Nine Posted July 28, 2020 Posted July 28, 2020 @halbum2040 If you are to set Bitmap to Ctrl multiple times, you need to delete old objects otherwise you will face a massive memory leak. I am talking from experience here Use something like this : Local $hPrev = _SendMessage($hWnd, $STM_SETIMAGE, $SS_IMAGE_BITMAP, $hBitmap) If @error Then Return SetError(1, 0, 0) If $hPrev Then _WinAPI_DeleteObject($hPrev) It is a good practice to have this function modified anyway... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
halbum2040 Posted July 28, 2020 Author Posted July 28, 2020 Nine, I modified my code by pointing out what I didn't think of. I'm glad to know the memory leak. Thank you for your advice that has grown me even more. Nine 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now