【发布时间】:2016-11-02 05:20:39
【问题描述】:
我的任务是分割屏幕截图并像网格一样循环浏览屏幕截图,将每个预定义块保存为自己的图像,就像下图一样。实际网格大小是 10X8 它一直跳过第 2 列。请告诉我我的逻辑缺陷,因为我在过去 3 天里用 10 种不同的方式重写了 if 块 100 次,但无济于事。
Col1 Col2 Col3
Row1 1 2 3
Row2 4 5 6
Row3 7 8 9
“开始为每个球循环图像”
[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]$单元格宽度 = 100
[int]$偏移量 = 2
做
{
#获取当前时间并从中构建文件名
$Time =(获取日期)
[字符串] $FileName += "-cellshot"
$FileName = "$($Time.Month)"
$文件名 += '-'
$FileName += "$($Time.Day)"
$文件名 += '-'
$FileName += "$($Time.Year)"
$文件名 += '-'
$FileName += "$($Time.Hour)"
$文件名 += '-'
$FileName += "$($Time.Minute)"
$文件名 += '-'
$FileName += "$($Time.Second)"
$文件名 += '-'
$FileName += "$($Time.Millisecond)"
$文件名 += '-'
$FileName += [字符串]$currentCell
$文件名 += '.png'
#use join-path 添加路径到文件名
[字符串] $FilePath = (加入路径 $Path $FileName)
if (!$currentCell -OR !$currentColumn -OR !$currentRow){
“初始化全局”
$currentCell = $startCell
$currentColumn = $startColumn
$currentRow = $startRow
}
“指定捕获点”
if ($currentColumn -gt 1 -AND $currentColumn -lt 11) {
“计算侧坐标偏移”
$newleftCoord = $startleftCoord+($currentColumn*$cellwidth)
$newrightCoord = $startrightCoord+($currentColumn*$cellwidth)
} elseif ($currentColumn -eq 11) {
“重置列坐标”
$currentColumn = $startColumn
$newleftCoord = $startleftCoord
$newrightCoord = $startrightCoord
“补偿多行错误”
$newtopCoord = $starttopCoord+($currentRow*$cellheight)+$offset
$newbottomCoord = $startbottomCoord+($currentRow*$cellheight)+$offset
$currentRow++
}别的{
“获得第一”
$newleftCoord = $startleftCoord
$newtopCoord = $starttopCoord
$newrightCoord = $startrightCoord
$newbottomCoord = $startbottomCoord
}
“当前列是” + $currentColumn
“当前行是” + $currentRow
“当前单元格是” + $currentCell
#保存细胞截图
$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)
$当前列++
$currentCell++
}直到 ($currentCell -eq $totalLoops)
开始-睡眠-第二 20
}
#加载所需的程序集
Add-Type -Assembly System.Windows.Forms
开始-睡眠-秒 5
$ballarray = @{}
做 {
#运行截图功能
# if ($ballarray.count -eq 20){
# GenScreenshot
# "截图 - $Filename ."
# }别的{
做{
获取新球
}直到($currentCell -eq 80)
#}
#$bounds = [Drawing.Rectangle]::FromLTRB(307,129, 1060, 668)
#screenshot $bounds $文件路径
#Start-Sleep -Second 10
}直到($ballarray.count -eq 20)
【问题讨论】:
标签: powershell nested-loops do-while image-segmentation