Jump to content

Search the Community

Showing results for tags 'paint'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 4 results

  1. Hi all, I'm trying to find how to draw an image (create a label in mspaint) and save it as .bmp. And set it to be a wallpaper I also need to know what wallpaper is use now, for restore it when the script is closed. What is the best way to do it? Do I need Gdi+ for it? I use this code (which I found here in forum) to set a .bmp file as wallpaper: Func _ChangeWallpaper($sFile,$iType) ; Changes the wallpaper to $sFilename using $iType as: ; 1 Tiled ; 2 Centered ; 3 Stretched ; any other value (usually 0) unchanged ; ; Returns ; 0 if everything is allright. ; -1 if $sFile does not exist. @error is set to 1 ; -2 if £sFile is not a .bmp file. @error is set to 2 If Not FileExists($sFile) Then SetError(1) Return -1 EndIf If StringTrimLeft($sFile,StringInStr($sFile,'.',0,-1)) <> 'bmp' Then SetError(2) Return -2 EndIf Select Case $iType = 1 RegWrite('HKCU\Control Panel\Desktop','TileWallpaper','reg_sz','1') RegWrite('HKCU\Control Panel\Desktop','WallpaperStyle','reg_sz','0') Case $iType = 2 RegWrite('HKCU\Control Panel\Desktop','TileWallpaper','reg_sz','0') RegWrite('HKCU\Control Panel\Desktop','WallpaperStyle','reg_sz','0') Case $iType = 3 RegWrite('HKCU\Control Panel\Desktop','TileWallpaper','reg_sz','0') RegWrite('HKCU\Control Panel\Desktop','WallpaperStyle','reg_sz','2') Case Else EndSelect RegWrite('HKCU\Control Panel\Desktop','Wallpaper','reg_sz',$sFile) DllCall("User32.dll","int","SystemParametersInfo","int",20,"int",0,"str",$sFile,"int",0) Return 0 EndFunc The flow that I understand should be: 1) Check what wallpaper is in use now. I can find the path to it by going to registry key named "wallpaper" here :[HKEY_CURRENT_USER\Control Panel\Desktop] 2) Create a file mspaint 3) Create a label with its properties (size,color) in this file 3) Save this file in some temporary directory 4) Set a created file as a wallpaper using the above code 5) When the script is closed restore the old wallpaper. So again, my question is how to create a .bmp file with label in it?
  2. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=car.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GDIPlus.au3> #include <File.au3> #include <Array.au3> #include <ColorConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ProgressConstants.au3> ; Declare array Dim $Images[1] ; Gets all JPG files in the current directory (@ScriptDir). Local $search = FileFindFirstFile("*.jpg") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No JPG files could be found.") Exit EndIf ; Resize array While 1 If IsArray($Images) Then Local $Bound = UBound($Images) ReDim $Images[$Bound+1] EndIf $Images[$Bound] = FileFindNextFile($search) If @error Then ExitLoop WEnd ; Close the search handle FileClose($search) ; Create directory "resized" if not there yet $nymappe = InputBox("Mappe / Bil Navn", "Mappe / Bil Navn") If NOT FileExists(@ScriptDir & "\" & $nymappe & "\") Then DirCreate(@ScriptDir & "\" & $nymappe & "\") EndIf ; Loop for JPGs - gets dimension of JPG and calls resize function to resize to 50% width and 50% height For $i = 1 to Ubound($Images)-1 If $Images[$i] <> "" AND FileExists(@ScriptDir & "\" & $Images[$i]) Then Local $ImagePath = @ScriptDir & "\" & $Images[$i] _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($ImagePath) Local $ImageWidth = _GDIPlus_ImageGetWidth($hImage) Local $ImageHeight = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() ;MsgBox(0,"DEBUG", $ImageWidth & " x " & $ImageHeight) Local $NewImageWidth = ($ImageWidth / 100) * 15 Local $NewImageHeight = ($ImageHeight / 100) * 15 ;MsgBox(0,"DEBUG: " & $i,$Images[$i]) _ImageResize(@ScriptDir & "\" & $Images[$i], @ScriptDir & "\" & $nymappe & "\" & $Images[$i], $NewImageWidth, $NewImageHeight) EndIf Next ; Resize function Func _ImageResize($sInImage, $sOutImage, $iW, $iH) Local $hWnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0 ;OutFile path, to use later on. Local $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1)) ;OutFile name, to use later on. Local $sOF = StringMid($sOutImage, StringInStr($sOutImage, "\", 0, -1) + 1) ;OutFile extension , to use for the encoder later on. Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1)) ; Win api to create blank bitmap at the width and height to put your resized image on. $hWnd = _WinAPI_GetDesktopWindow() $hDC = _WinAPI_GetDC($hWnd) $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) _WinAPI_ReleaseDC($hWnd, $hDC) ;Start GDIPlus _GDIPlus_Startup() ;Get the handle of blank bitmap you created above as an image $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP) ;Load the image you want to resize. $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage) ;Get the graphic context of the blank bitmap $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1) ;Draw the loaded image onto the blank bitmap at the size you want _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH) ;Get the encoder of to save the resized image in the format you want. $CLSID = _GDIPlus_EncodersGetCLSID($Ext) ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image. Do $i += 1 Until (Not FileExists($sOP & $i & "_" & $sOF)) ;Prefix the number to the begining of the output filename $sOutImage = $sOP & $i & "_" & $sOF ;Save the new resized image. _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID) ;Clean up and shutdown GDIPlus. _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_GraphicsDispose ($hGraphic) _WinAPI_DeleteObject($hBMP) _GDIPlus_Shutdown() EndFunc Quality gets quite bad compared to using Paint / Photoshop when resizing with GDIPlus Any idea how to make the quality better? Thanks in advance
  3. Hello AutoIT masters I am gonna start writing a fun little script to resize X amount of images with the Horizontal/Vertical aspects to 15/15 instead of the standard 100/100 I need to be able to do this with X amount of images and after changing the dimensions I need to save all the images in a path. so to keep things simple. 1: File open prompt 2: Choose X amount of images 3: Automatically choose 15/15 for all images 4: Save in path chosen by user 5: Might be more to come. 6: the faster the better! I am gonna start this project tomorrow, any help/references is highly appreciated! Thanks in advance and Wish me luck #### I Hit a bump on the road ### I successfully manage to do what I want to do and I successfully manage to rewrite names but 3 of the image names won't rename? So lets say I have 10 images that all get resized, then 7 of them gets renamed but not the last three, confuses me quite a bit? Thanks in advance! Rename script: Func renameall() local $path = @ScriptDir & "\" & $nymappe & "\" local $ret Local $hSearch = FileFindFirstFile($path & "*.jpg") $i = 1 While 1 $sFileName = FileFindNextFile($hSearch) If @error Then ExitLoop if FileMove($path & $sFileName, $path & String("NewName" & +$i) & ".jpg", 0) = 1 then ConsoleWrite($path & $sFileName & ' renamed to ' & $path & String("NewName" & +$i) & ".jpg" & @LF) Else ConsoleWrite('File rename failed for file = ' & $path & $sFileName & @LF) endif $i += 1 WEnd FileClose($hSearch) EndFunc Full script: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=car.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GDIPlus.au3> #include <File.au3> #include <Array.au3> #include <ColorConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ProgressConstants.au3> ; Declare array Dim $Images[1] ; Gets all JPG files in the current directory (@ScriptDir). Local $search = FileFindFirstFile("*.jpg") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No JPG files could be found.") Exit EndIf ; Resize array While 1 If IsArray($Images) Then Local $Bound = UBound($Images) ReDim $Images[$Bound+1] EndIf $Images[$Bound] = FileFindNextFile($search) If @error Then ExitLoop WEnd ; Close the search handle FileClose($search) ; Create directory "resized" if not there yet $nymappe = InputBox("Mappe / Bil Navn", "Mappe / Bil Navn") If NOT FileExists(@ScriptDir & "\" & $nymappe & "\") Then DirCreate(@ScriptDir & "\" & $nymappe & "\") EndIf ; Loop for JPGs - gets dimension of JPG and calls resize function to resize to 50% width and 50% height For $i = 1 to Ubound($Images)-1 If $Images[$i] <> "" AND FileExists(@ScriptDir & "\" & $Images[$i]) Then Local $ImagePath = @ScriptDir & "\" & $Images[$i] _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($ImagePath) Local $ImageWidth = _GDIPlus_ImageGetWidth($hImage) Local $ImageHeight = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() ;MsgBox(0,"DEBUG", $ImageWidth & " x " & $ImageHeight) Local $NewImageWidth = ($ImageWidth / 100) * 15 Local $NewImageHeight = ($ImageHeight / 100) * 15 ;MsgBox(0,"DEBUG: " & $i,$Images[$i]) _ImageResize(@ScriptDir & "\" & $Images[$i], @ScriptDir & "\" & $nymappe & "\" & $Images[$i], $NewImageWidth, $NewImageHeight) EndIf Next ; Resize function Func _ImageResize($sInImage, $sOutImage, $iW, $iH) Local $hWnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0 ;OutFile path, to use later on. Local $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1)) ;OutFile name, to use later on. Local $sOF = StringMid($sOutImage, StringInStr($sOutImage, "\", 0, -1) + 1) ;OutFile extension , to use for the encoder later on. Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1)) ; Win api to create blank bitmap at the width and height to put your resized image on. $hWnd = _WinAPI_GetDesktopWindow() $hDC = _WinAPI_GetDC($hWnd) $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) _WinAPI_ReleaseDC($hWnd, $hDC) ;Start GDIPlus _GDIPlus_Startup() ;Get the handle of blank bitmap you created above as an image $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP) ;Load the image you want to resize. $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage) ;Get the graphic context of the blank bitmap $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1) ;Draw the loaded image onto the blank bitmap at the size you want _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH) ;Get the encoder of to save the resized image in the format you want. $CLSID = _GDIPlus_EncodersGetCLSID($Ext) ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image. Do $i += 1 Until (Not FileExists($sOP & $i & "_" & $sOF)) ;Prefix the number to the begining of the output filename $sOutImage = $sOP & $i & "_" & $sOF ;Save the new resized image. _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID) ;Clean up and shutdown GDIPlus. _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_GraphicsDispose ($hGraphic) _WinAPI_DeleteObject($hBMP) _GDIPlus_Shutdown() Call("renameall") EndFunc Func renameall() local $path = @ScriptDir & "\" & $nymappe & "\" local $ret Local $hSearch = FileFindFirstFile($path & "*.jpg") $i = 1 While 1 $sFileName = FileFindNextFile($hSearch) If @error Then ExitLoop if FileMove($path & $sFileName, $path & String("NewName" & +$i) & ".jpg", 0) = 1 then ConsoleWrite($path & $sFileName & ' renamed to ' & $path & String("NewName" & +$i) & ".jpg" & @LF) Else ConsoleWrite('File rename failed for file = ' & $path & $sFileName & @LF) endif $i += 1 WEnd FileClose($hSearch) EndFunc
  4. Hello again the AutoIt Forums! I've gotten really addicted to the GDIPlus stuff and I'm trying to do more. Trying to create small editor using GDIPlus and I'm a bit lost just getting started. The main GUI is small, so when I you Snip an area that's larger than the GUI it would only display as large as the GUI (I got around this by setting an event for WM_WINDOWPOSCHANGING but it flickers really badly). I tried doing something by setting the bitmap to a GUICtrlCreatePic control but it still flickered. So essentially I need a way to create a graphics larger than the GUI itself and I don't know how to do something like that. I thought it would have been _GDIPlus_GraphicsCreateFromHDC but it still wasn't create it properly. I did a lot of googling and this topic has a lot of great info in it and I will probably incorporate scrollbars too, later, but UEZ didn't give the secret to resizing! Lol I've got the source code for vPaint downloaded, and I've started to through some of it (But like the author said, the source code is messy and things are out of order) so it may take a while. #include <GDIPlus.au3> #include <File.au3> #include <GUIConstants.au3> #include <String.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <ScreenCapture.au3> #include <Color.au3> #include <Misc.au3> #include <WinAPISys.au3> #include <GuiToolbar.au3> #include <GuiImageList.au3> #include <Array.au3> AutoItSetOption("GuiOnEventMode", 1) AutoItSetOption("MustDeclareVars", 1) HotKeySet("{Esc}", "ClosePixShop") Global $frm_pixshop_abscoord[4] = [100, 100, 400, 200] Global $frmPixShop Global $tlbPixShopToolbar Global $hWnd_toolbar_image_list Global $hWnd_dll = DllOpen("user32.dll") Global $frm_pixshop_state = @SW_HIDE Global $hWnd_bitmaps[1] Global $picBitmaps[1] Global $abscoord_bitmaps[1][2] = [[0, 0]] Global $abscoord_graphics[4] = [8, 46, 0, 0] Global $pixshop_buffer[1] Global Enum $idToolbarStart = 1000, $idMouse, $idSnip, $idCrop, $idText, $idBrush, $idToolbarEnd Global $hWnd_pixshop_graphics Global $hWnd_pixshop_bitmap Global $hWnd_pixshop_buffer PixShop() Func PixShop() $frmPixShop = GUICreate("PixShop", $frm_pixshop_abscoord[2], $frm_pixshop_abscoord[3], $frm_pixshop_abscoord[0], $frm_pixshop_abscoord[1], $WS_SIZEBOX, $WS_EX_TOPMOST) $tlbPixShopToolbar = _GUICtrlToolbar_Create($frmPixShop, $TBSTYLE_TRANSPARENT) GUICtrlCreateLabel("", 0, 36, $frm_pixshop_abscoord[2], $frm_pixshop_abscoord[3], -1, $WS_EX_LAYERED) GUICtrlSetBkColor(-1, 0x0D0D0D) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM) GUISetBkColor(0x535353, $frmPixShop) $hWnd_toolbar_image_list = _GUIImageList_Create(24, 24, 5, 5) _GUIImageList_AddIcon($hWnd_toolbar_image_list, @ScriptDir & "\Icons\Mouse.ico") _GUIImageList_AddIcon($hWnd_toolbar_image_list, @ScriptDir & "\Icons\Snip.ico") _GUIImageList_AddIcon($hWnd_toolbar_image_list, @ScriptDir & "\Icons\Crop.ico") _GUIImageList_AddIcon($hWnd_toolbar_image_list, @ScriptDir & "\Icons\Text.ico") _GUIImageList_AddIcon($hWnd_toolbar_image_list, @ScriptDir & "\Icons\Brush.ico") _GUICtrlToolbar_SetImageList($tlbPixShopToolbar, $hWnd_toolbar_image_list) _GUICtrlToolbar_SetIndent($tlbPixShopToolbar, 2) _GUICtrlToolbar_AddButton($tlbPixShopToolbar, $idMouse, 0) _GUICtrlToolbar_AddButton($tlbPixShopToolbar, $idSnip, 1) _GUICtrlToolbar_AddButton($tlbPixShopToolbar, $idCrop, 2) _GUICtrlToolbar_AddButton($tlbPixShopToolbar, $idText, 3) _GUICtrlToolbar_AddButton($tlbPixShopToolbar, $idBrush, 4) _GUICtrlToolbar_SetColorScheme($tlbPixShopToolbar, 0x535353, 0x535353) _GUICtrlToolbar_CheckButton($tlbPixShopToolbar, $idMouse, True) GUISetOnEvent($GUI_EVENT_CLOSE, "ClosePixShop") ; Register the WM_GETMINMAXINFO function GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO") ; Register the WM_NOTIFY function GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING") GUIRegisterMsg($WM_PAINT, "WM_PAINT") GUISetState(@SW_SHOW, $frmPixShop) _GDIPlus_Startup() While (True) Sleep(100) WEnd EndFunc ;==>PixShop Func ClosePixShop() _GDIPlus_GraphicsDispose($hWnd_pixshop_graphics) _GDIPlus_BitmapDispose($hWnd_pixshop_bitmap) For $i = 0 To UBound($hWnd_bitmaps) - 1 _WinAPI_DeleteObject($hWnd_bitmaps[$i]) Next DllClose($hWnd_dll) Exit (0) EndFunc ;==>ClosePixShop Func WM_PAINT($hWndFrom, $iMsg, $wParam, $lParam) #forceref $hWndFrom, $iMsg, $wParam, $lParam DrawPixShopGraphics() EndFunc ;==>WM_PAINT Func WM_NOTIFY($hWndFrom, $iMsg, $wParam, $lParam) #forceref $hWndFrom, $iMsg, $wParam, $lParam Local $tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam) Local $tlbCode = DllStructGetData($tNMTOOLBAR, "Code") Local $iItem = DllStructGetData($tNMTOOLBAR, "iItem") Local $id_checked_button If ($tlbCode = $TBN_BEGINDRAG) Then If (Not _GUICtrlToolbar_IsButtonChecked($tlbPixShopToolbar, $iItem)) Then For $id = $idToolbarStart + 1 To $idToolbarEnd - 1 If (_GUICtrlToolbar_IsButtonChecked($tlbPixShopToolbar, $id)) Then $id_checked_button = $id _GUICtrlToolbar_CheckButton($tlbPixShopToolbar, $id, False) EndIf Next _GUICtrlToolbar_CheckButton($tlbPixShopToolbar, $iItem, True) EndIf Switch $iItem ; Button pressed was the $idColor button Case $idSnip Local $abscoord_frm_pixshop = WinGetPos($frmPixShop) While (_IsPressed("01", $hWnd_dll)) Sleep(10) WEnd GUISetState(@SW_HIDE, $frmPixShop) $hWnd_bitmaps[UBound($hWnd_bitmaps) - 1] = SnipArea($abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1][0], $abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1][1]) $pixshop_buffer[UBound($pixshop_buffer) - 1] = "SnippedImage|" & $hWnd_bitmaps[UBound($hWnd_bitmaps) - 1] ReDim $hWnd_bitmaps[UBound($hWnd_bitmaps)] ReDim $pixshop_buffer[UBound($pixshop_buffer)] If ($abscoord_graphics[2] = 0 And $abscoord_graphics[3] = 0) Then $abscoord_graphics[2] = $abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1][0] $abscoord_graphics[3] = $abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1][1] $pixshop_buffer[UBound($pixshop_buffer) - 1] = "ResizeGraphics|0,0-" & $abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1][0] & ',' & $abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1][1] ReDim $pixshop_buffer[UBound($pixshop_buffer)] #cs If (IsArray($abscoord_frm_pixshop)) Then If ($abscoord_frm_pixshop[2] < $abscoord_graphics[2]) Then WinMove($frmPixShop, "", $abscoord_frm_pixshop[0], $abscoord_frm_pixshop[1], $abscoord_graphics[2] + 24, $abscoord_frm_pixshop[3]) $abscoord_frm_pixshop[2] = $abscoord_graphics[2] + 24 EndIf If ($abscoord_frm_pixshop[3] < $abscoord_graphics[3]) Then WinMove($frmPixShop, "", $abscoord_frm_pixshop[0], $abscoord_frm_pixshop[1], $abscoord_frm_pixshop[2], $abscoord_graphics[3] + 46) $abscoord_frm_pixshop[3] = $abscoord_graphics[3] + 54 EndIf EndIf #ce EndIf ReDim $abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS)][2] GUISetState(@SW_SHOW, $frmPixShop) ResizePixShopGraphics() DrawPixShopGraphics() _GUICtrlToolbar_CheckButton($tlbPixShopToolbar, $iItem, False) _GUICtrlToolbar_CheckButton($tlbPixShopToolbar, $id_checked_button, True) Case $idCrop ToolTip("Crop Image") Case $idText ToolTip("Add Text") Case $idBrush ToolTip("Brush Image") EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func DrawPixShopGraphics() Local $hWnd_bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hWnd_bitmaps[0]) _GDIPlus_GraphicsClear($hWnd_pixshop_buffer, 0x00000000) _GDIPlus_GraphicsDrawImageRect($hWnd_pixshop_buffer, $hWnd_bitmap, $abscoord_graphics[0], $abscoord_graphics[1], $abscoord_graphics[2], $abscoord_graphics[3]) _GDIPlus_ImageDispose($hWnd_bitmap) _GDIPlus_GraphicsDrawImage($hWnd_pixshop_graphics, $hWnd_pixshop_bitmap, 0, 0) EndFunc ;==>DrawPixShopGraphics Func SnipArea(ByRef $snipped_image_width, ByRef $snipped_image_height) Local $abscoord_mouse Local $hMask Local $hMaster_Mask Local $temp_val Local $mouse_x_1 Local $mouse_y_1 Local $mouse_x_2 Local $mouse_y_2 ToolTip("Left click and drag to select the area", 0, 0) Local $frmOverlay = GUICreate("GUI Overlay", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST) WinSetTrans($frmOverlay, "", 1) GUISetBkColor(0x000000, $frmOverlay) GUISetState(@SW_SHOW, $frmOverlay) GUISetCursor(3, 1, $frmOverlay) Local $frmSnipArea = GUICreate("GUI Snip", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) GUISetBkColor(0xFF0000) ; Wait until mouse button pressed While (Not _IsPressed("01", $hWnd_dll)) Sleep(10) WEnd ; Get first mouse position $abscoord_mouse = MouseGetPos() $mouse_x_1 = $abscoord_mouse[0] $mouse_y_1 = $abscoord_mouse[1] ; Draw rectangle while mouse button pressed While _IsPressed("01", $hWnd_dll) $abscoord_mouse = MouseGetPos() $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0) $hMask = _WinAPI_CreateRectRgn($mouse_x_1, $abscoord_mouse[1], $abscoord_mouse[0], $abscoord_mouse[1] + 1) ; Bottom of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($mouse_x_1, $mouse_y_1, $mouse_x_1 + 1, $abscoord_mouse[1]) ; Left of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($mouse_x_1 + 1, $mouse_y_1 + 1, $abscoord_mouse[0], $mouse_y_1) ; Top of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($abscoord_mouse[0], $mouse_y_1, $abscoord_mouse[0] + 1, $abscoord_mouse[1]) ; Right of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) ; Set overall region _WinAPI_SetWindowRgn($frmSnipArea, $hMaster_Mask) If WinGetState($frmSnipArea) < 15 Then GUISetState() Sleep(10) WEnd ToolTip("") ; Get second mouse position $mouse_x_2 = $abscoord_mouse[0] $mouse_y_2 = $abscoord_mouse[1] ; Set in correct order if required If $mouse_x_2 < $mouse_x_1 Then $temp_val = $mouse_x_1 $mouse_x_1 = $mouse_x_2 $mouse_x_2 = $temp_val EndIf If $mouse_y_2 < $mouse_y_1 Then $temp_val = $mouse_y_1 $mouse_y_1 = $mouse_y_2 $mouse_y_2 = $temp_val EndIf GUIDelete($frmSnipArea) GUIDelete($frmOverlay) $snipped_image_width = $mouse_x_2 - $mouse_x_1 $snipped_image_height = $mouse_y_2 - $mouse_y_1 Return _ScreenCapture_Capture("", $mouse_x_1, $mouse_y_1, $mouse_x_2, $mouse_y_2, False) EndFunc ;==>SnipArea Func ResizePixShopGraphics() Local $graphics_width Local $graphics_height _GDIPlus_GraphicsDispose($hWnd_pixshop_graphics) _GDIPlus_BitmapDispose($hWnd_pixshop_bitmap) For $i = 0 To UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1 $graphics_width += $abscoord_bitmaps[$i][0] $graphics_height += $abscoord_bitmaps[$i][1] Next $hWnd_pixshop_graphics = _GDIPlus_GraphicsCreateFromHWND($frmPixShop) $hWnd_pixshop_bitmap = _GDIPlus_BitmapCreateFromGraphics($graphics_width, $graphics_height, $hWnd_pixshop_graphics) $hWnd_pixshop_buffer = _GDIPlus_ImageGetGraphicsContext($hWnd_pixshop_bitmap) _GDIPlus_GraphicsSetSmoothingMode($hWnd_pixshop_buffer, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hWnd_pixshop_graphics, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT) EndFunc ;==>ResizePixShopGraphics Func WM_WINDOWPOSCHANGING($hWndFrom, $iMsg, $wParam, $lParam) #forceref $hWndFrom, $iMsg, $wParam, $lParam If ($hWndFrom <> $frmPixShop) Then Return $GUI_RUNDEFMSG Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam) Local $iLeft = DllStructGetData($stWinPos, 3) Local $iTop = DllStructGetData($stWinPos, 4) Local $iWidth = DllStructGetData($stWinPos, 5) Local $iHeight = DllStructGetData($stWinPos, 6) ResizePixShopGraphics() DrawPixShopGraphics() Return $GUI_RUNDEFMSG EndFunc ;==>WM_WINDOWPOSCHANGING Func WM_GETMINMAXINFO($hWndFrom, $iMsg, $wParam, $lParam) #forceref $hWndFrom, $iMsg, $wParam, $lParam Local $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam) DllStructSetData($tagMaxinfo, 7, 300) ; Set MIN width DllStructSetData($tagMaxinfo, 8, 200) ; Set MIN height Return $GUI_RUNDEFMSG EndFunc ;==>WM_GETMINMAXINFO
×
×
  • Create New...