Мне поручено сегментировать скриншот и прокручивать скриншот, как сетка, сохраняющая каждый предопределенный блок как свой собственный образ, как диаграмма ниже. Фактический размер сетки - 10X8. Он продолжает пропускать колонку 2. Пожалуйста, просветите меня по моему логическому изъяну, поскольку я переписал блок if 100 раз, 10 различных способов за последние 3 дня безрезультатно.В то время как сегментирование изображения, цикл пропускает полный столбец
Col1 Col2 Col3
Row1 1 2 3
Row2 4 5 6
Row3 7 8 9
"Starting to loop image for each ball" [int]$startCell = 1 [int]$startRow = 1 [int]$startColumn = 1 [int]$totalLoops = 81 [int]$startleftCoord = 293 [int]$starttopCoord = 90 [int]$startrightCoord = 385 [int]$startbottomCoord = 160 [int]$cellheight = 75 [int]$cellwidth = 100 [int]$offset = 2 Do { #get the current time and build the filename from it $Time = (Get-Date) [string] $FileName += "-cellshot" $FileName = "$($Time.Month)" $FileName += '-' $FileName += "$($Time.Day)" $FileName += '-' $FileName += "$($Time.Year)" $FileName += '-' $FileName += "$($Time.Hour)" $FileName += '-' $FileName += "$($Time.Minute)" $FileName += '-' $FileName += "$($Time.Second)" $FileName += '-' $FileName += "$($Time.Millisecond)" $FileName += '-' $FileName += [string]$currentCell $FileName += '.png' #use join-path to add path to filename [string] $FilePath = (Join-Path $Path $FileName) if (!$currentCell -OR !$currentColumn -OR !$currentRow){ "Initializing Globals" $currentCell = $startCell $currentColumn = $startColumn $currentRow = $startRow } "Designate capture point" if ($currentColumn -gt 1 -AND $currentColumn -lt 11) { "Calculating side coordinates offset" $newleftCoord = $startleftCoord+($currentColumn*$cellwidth) $newrightCoord = $startrightCoord+($currentColumn*$cellwidth) } elseif ($currentColumn -eq 11) { "Resetting column coordinates " $currentColumn = $startColumn $newleftCoord = $startleftCoord $newrightCoord = $startrightCoord "Compensating for multiple rows offest" $newtopCoord = $starttopCoord+($currentRow*$cellheight)+$offset $newbottomCoord = $startbottomCoord+($currentRow*$cellheight)+$offset $currentRow++ }else{ "Getting number one" $newleftCoord = $startleftCoord $newtopCoord = $starttopCoord $newrightCoord = $startrightCoord $newbottomCoord = $startbottomCoord } "Current Column is " + $currentColumn "Current row is " + $currentRow "Current cell is " + $currentCell #save cellshot $cellBounds = [Drawing.Rectangle]::FromLTRB($newleftCoord,$newtopCoord, $newrightCoord, $newbottomCoord) $cellObject = New-Object Drawing.Bitmap $cellBounds.Width, $cellBounds.Height $cellGraphics = [Drawing.Graphics]::FromImage($cellObject) $cellGraphics.CopyFromScreen($cellBounds.Location, [Drawing.Point]::Empty, $cellBounds.Size) $cellGraphics.Dispose() $cellObject.Save($FilePath) $currentColumn++ $currentCell++ }Until ($currentCell -eq $totalLoops) Start-Sleep -Second 20 } #load required assembly Add-Type -Assembly System.Windows.Forms Start-Sleep -Seconds 5 $ballarray = @{} Do { #run screenshot function # If ($ballarray.count -eq 20){ # GenScreenshot # "Snapped screenshot - $Filename ." # }else{ Do{ GetNewBall }Until($currentCell -eq 80) #} #$bounds = [Drawing.Rectangle]::FromLTRB(307,129, 1060, 668) #screenshot $bounds $Filepath #Start-Sleep -Second 10 }Until($ballarray.count -eq 20)
Большое спасибо, что нашли время. Для дальнейшего уточнения относительно того, «как и почему» я получал результаты, я был. Ваше «исправление» было именно таким решением. Я тебе завидую. @TessellatingHeckler Спасибо за вашу щедрость. Я вношу свой вклад и остаюсь активным в сообществе, чтобы получить свою репутацию выше 15, а затем кредит на ваш ответ. До тех пор, надеюсь, кто-то прогуливается и голосует. – Eric
@Eric Спасибо :) Если вы еще этого не сделали, посмотрите на PowerShell ISE - он поставляется с Windows - откройте в нем свой скрипт, нажмите на некоторый код в верхней части цикла, перейдите в «Debug -> Toggle Breakpoint» (или клавишу F9), линия становится красной - попробуйте разные строки до тех пор, пока вы не сделаете это. Затем 'Debug -> Run/Continue' (F5), он будет работать и останавливаться на этой строке. Вы можете «Debug -> Step Over» (F10 и F11) по одной строке за раз. На самом деле полезно навести указатель мыши на переменные и увидеть их значения. Найдите, когда позиция столбца изменится неправильно и почему. Выполнить код в приглашении '[DBG]: PS >>', выставить в приостановленном состоянии. – TessellatingHeckler
(PS, если вы хотите, вы можете поставить галочку под стрелками голосования и «принять» мой ответ, который отмечает ваш вопрос как «ответил» и дает мне очки). – TessellatingHeckler