Leaderboard
Popular Content
Showing content with the highest reputation on 03/16/2024 in all areas
-
BIG THANKS to @UEZ for his code, which I adapted, plus adding some of my own. See his post here. I spent quite a while trying to come up with something simple to include in a program of mine. The examples in the Help file didn't quite do it for me, some very complex. Here's an image I needed to rotate by 1 degree right, and then trim and resize, for embedding into my FLAC and MP3 files for that album. The image was sourced from eBay, as alas Discogs let me down. Admittedly the album title wasn't very helpful, and there are two other volumes, though I only have the first one. Anyway, I have provided the image, so you can test and play around with it. #include <GDIPlus.au3> ; BIG THANKS to UEZ ; I modified his example from - https://www.autoitscript.com/forum/topic/155932-gdiplus-need-help-with-rotating-an-image/?do=findComment&comment=1127106 Global $hBackbuffer, $hBitmap, $hBitmap_Scaled, $hClone, $hCoverBitmap, $hCoverGC, $hCoverMatrix, $hCoverTexture, $hGraphic, $iH, $inifile, $iW, $newfile, $sCLSID $inifile = @ScriptDir & "\Settings.ini" $newfile = @ScriptDir & "\rotated.jpg" If FileExists($newfile) Then FileDelete($newfile) _GDIPlus_Startup() $hCoverTexture = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\cover.jpg") $iW = _GDIPlus_ImageGetWidth($hCoverTexture) $iH = _GDIPlus_ImageGetHeight($hCoverTexture) $iW = $iW / 2 $iH = $iH / 2 $hBitmap_Scaled = _GDIPlus_ImageResize($hCoverTexture, $iW, $iH, 5) Global $hGUI = GUICreate("", $iW, $iH) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphic) $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) $hCoverBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hBackbuffer) $hCoverGC = _GDIPlus_ImageGetGraphicsContext($hCoverBitmap) $hCoverMatrix = _GDIPlus_MatrixCreate() Rotate() Sleep(1000) Local $crop = 1, $resize = 1, $trim If $crop = 1 Then Local $lft = IniRead($inifile, "Image Crop", "left", 0) Local $tp = IniRead($inifile, "Image Crop", "top", 0) Local $wd = IniRead($inifile, "Image Crop", "width", $iW) Local $ht = IniRead($inifile, "Image Crop", "height", $iH) Local $size = $lft & "_" & $tp & "_" & $wd & "_" & $ht ; $trim = InputBox("Crop Query", "Please set the desired values." & @LF & @LF & "Left_Top_Width_Height", $size, "", 200, 160, Default, Default) If @error = 0 Then $trim = StringSplit($trim, "_", 1) If $trim[0] = 4 Then $lft = $trim[1] $tp = $trim[2] $wd = $trim[3] $ht = $trim[4] IniWrite($inifile, "Image Crop", "left", $lft) IniWrite($inifile, "Image Crop", "top", $tp) IniWrite($inifile, "Image Crop", "width", $wd) IniWrite($inifile, "Image Crop", "height", $ht) If $wd < 1 Then $wd = $iW EndIf If $ht < 1 Then $ht = $iH EndIf If $lft < 1 Then $lft = 0 EndIf If $tp < 1 Then $tp = 0 EndIf $wd = $wd - $lft $ht = $ht - $tp ; 188_55_630_496 $hClone = _GDIPlus_BitmapCloneArea($hBitmap, $lft, $tp, $wd, $ht, $GDIP_PXF24RGB) Else MsgBox(262192, "Crop Error", "Wrong number of values specified. 4 required.", 0, $DropboxGUI) EndIf EndIf Else $hClone = "none" EndIf If $resize = 1 Then If $hClone = "none" Then $hClone_Scaled = _GDIPlus_ImageResize($hBitmap, 600, 600, 5) Else $hClone_Scaled = _GDIPlus_ImageResize($hClone, 600, 600, 5) EndIf Else $hClone_Scaled = $hBitmap EndIf $sCLSID = _GDIPlus_EncodersGetCLSID("JPG") _GDIPlus_ImageSaveToFileEx($hClone_Scaled, $newfile, $sCLSID) If FileExists($newfile) Then ShellExecute($newfile) GUIDelete($hGUI) _GDIPlus_BitmapDispose($hBitmap_Scaled) _GDIPlus_BitmapDispose($hClone_Scaled) If $hClone <> "none" Then _GDIPlus_ImageDispose($hClone) _GDIPlus_MatrixDispose($hCoverMatrix) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($hCoverGC) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_BitmapDispose($hCoverBitmap) _GDIPlus_BitmapDispose($hCoverTexture) _GDIPlus_ImageDispose($hBackbuffer) _GDIPlus_Shutdown() Exit Func Rotate() _GDIPlus_GraphicsClear($hBackbuffer, 0xFF6495ED) _GDIPlus_MatrixTranslate($hCoverMatrix, 0, 0) ; move it back to 0, 0 since (112 / 2) and (37 / 2) are it's middle origin point _GDIPlus_MatrixRotate($hCoverMatrix, 1) ; rotate it around it's middle origin point (minus to rotate left) _GDIPlus_GraphicsSetTransform($hCoverGC, $hCoverMatrix) _GDIPlus_MatrixTranslate($hCoverMatrix, 0, 0) _GDIPlus_GraphicsClear($hCoverGC, 0xFFFFFFFF) ; show the GC _GDIPlus_GraphicsDrawImageRect($hCoverGC, $hCoverTexture, 0, 0, $iW, $iH) ; place the arrow at the center of it's GC _GDIPlus_GraphicsDrawImage($hBackbuffer, $hCoverBitmap, 0, 0) ; move it's GC by an offset so the image is at the correct XY using it's origin _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH) EndFunc Resulting image. Enjoy! P.S. I should have probably removed the comments by UEZ in the Rotate function, especially as I changed it to not rotate around the center. Some of the code in that function is likely redundant too, because of that change.3 points
-
Hi @TheSaint Here a fast hack how to rotate the image by drawing a line on the edge of the CD cover to give you more flexibility. ;Coded by UEZ 2024-03-16 #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global $sFile = "cover.jpg" ;FileOpenDialog("Select an image", "", "Images (*.jpg;*.png;*.gif;*.bmp)") If @error Then Exit Const $fPI = ACos(-1) _GDIPlus_Startup() Global $hImage = _GDIPlus_ImageLoadFromFile($sFile), $hImage_rotated Global $aDim = _GDIPlus_ImageGetDimension($hImage) Global Const $hGUI = GUICreate("Image Rotate", $aDim[0], $aDim[1]) Global Const $hDC = _WinAPI_GetDC($hGUI) Global Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $aDim[0], $aDim[1]) Global Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Global Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) Global Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) Global Const $hPen = _GDIPlus_PenCreate(0xFFFFFFFF) _GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4) _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage, 0, 0, $aDim[0], $aDim[1]) GUISetCursor(3, 0, $hGUI) GUISetState() Global $aCI, $c = 0, $x1, $y1, $x2, $y2 Do _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage, 0, 0, $aDim[0], $aDim[1]) $aCI = GUIGetCursorInfo($hGUI) If $aCI[2] Then While GUIGetCursorInfo($hGUI)[2] Sleep(1) WEnd $c += 1 Switch $c Case 1 $x1 = $aCI[0] $y1 = $aCI[1] Case 2 $x2 = $aCI[0] $y2 = $aCI[1] EndSwitch EndIf Switch $c Case 1 _GDIPlus_GraphicsDrawLine($hCanvas, $x1, $y1, $aCI[0], $aCI[1], $hPen) Case 2 _GDIPlus_GraphicsDrawLine($hCanvas, $x1, $y1, $x2, $y2, $hPen) EndSwitch _WinAPI_BitBlt($hDC, 0, 0, $aDim[0], $aDim[1], $hDC_backbuffer, 0, 0, $SRCCOPY) If $aCI[3] Then ExitLoop Sleep(10) Until False _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage, 0, 0, $aDim[0], $aDim[1]) _GDIPlus_ImageRotate($hImage, 360 - CalculateAngle($x1, $y1, $x2, $y2)) $hImage_rotated = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) ;save result _GDIPlus_GraphicsClear($hCanvas) Do _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage_rotated, 0, 0, $aDim[0], $aDim[1]) _WinAPI_BitBlt($hDC, 0, 0, $aDim[0], $aDim[1], $hDC_backbuffer, 0, 0, $SRCCOPY) Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_ReleaseDC($hGUI, $hDC) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _GDIPlus_PenDispose($hPen) _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hImage_rotated) _GDIPlus_Shutdown() Func CalculateAngle($x1, $y1, $x2, $y2) Return ATan(($y2 - $y1) / ($x2 - $x1)) * (180 / $fPi) + ($x1 > $x2 ? 180 : ($y1 > $y2 ? 360 : 0)) EndFunc Func _GDIPlus_ImageRotate($hImage, $fDegree) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $fDegree = ' & $fDegree & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixTranslate($hMatrix, $aDim[0] / 2, $aDim[1] / 2) _GDIPlus_MatrixRotate($hMatrix, $fDegree) _GDIPlus_MatrixTranslate($hMatrix, -$aDim[0] / 2, -$aDim[1] / 2) _GDIPlus_GraphicsSetTransform($hCanvas, $hMatrix) _GDIPlus_MatrixDispose($hMatrix) EndFunc After you have started the script and the image is displayed click (lmb) on the left upper corner of the CD cover move the move the mouse to the right upper corner of the CD cover and press click the lmb again press the right mouse button The image should be rotated according to the angle of x1, y1 and x2, y2. You may add a crop function to get only a desired area of the image. 😉2 points
-
Am I missing something here (other than zero code that shows an attempt)? Are we to assume you want us to write the code to read the column into an array, that you have a magical array that you've already extracted and don't know how to enum the values, that you don't understand a function that reads the column and row values from the listview? Right there I've nearly added more information than the copy and paste script you provided from Koda. Do yourself a favor, when I googled your question with "Site: AutoIt" and used the term listview into array, I found NUMEROUS values... try that.2 points
-
You can do something like this to read the first email or select an item from listview and press the button to read the selected email: #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form2", 250, 250, 302, 218) $ListView1 = GUICtrlCreateListView("MyID|MyEmail|MyPAssword", 0, 0, 250, 180) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 70) $ListView1_0 = GUICtrlCreateListViewItem("102|test@mailcom|Pass1", $ListView1) $ListView2_0 = GUICtrlCreateListViewItem("103|another@mailcom|Pass2", $ListView1) $cRead = GUICtrlCreateButton('Read selected email', 50, 200, 150, 30) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $aSplit = StringSplit(GUICtrlRead($ListView1_0), '|') MsgBox(0, 'First email', $aSplit[2]) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $cRead $aSplit = StringSplit(GUICtrlRead(GUICtrlRead($ListView1)), '|') MsgBox(0, 'Selected email', $aSplit[2]) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd0 points