mercredi 26 octobre 2016

If statement within for loop not executing upon loop

I've been trying for days, and can not grasp the logic here. Throwing in the towel.

I have a image object I'm to chop it into a 10" x 8" grid of equal cells. After the 10th column its suppose to drop to the next row and gather the subsequent 10 columns and so forth. I cant seem to get it to recurse to the next row and stay put on that row, rather, it gets one cell and reverts back to the first row.

        $startColumn = 1
        $currentCell = 1
        $currentColumn = 1
        $currentRow = 1

        For($i = 1; $i -lt 81; $i++) 
        {
            $startleftCoord = 292
            $starttopCoord = 87
            $startrightCoord = 390
            $startbottomCoord = 162
            $cellheight = 75
            $cellwidth = 98



                if ($firstiterationcomplete -eq 1) {


                 "Changing columns"
                 $startleftCoord = $startleftCoord+($currentColumn*$cellwidth)+(4.05*$currentColumn)
                 $startrightCoord = $startrightCoord+($currentColumn*$cellwidth)+(4.05*$currentColumn)


                    if ($currentColumn -eq 9) {
                        "Changing Rows"                    
                        $currentRow++
                        $currentColumn = $startColumn

                        $startleftCoord = $startleftCoord
                        $startrightCoord = $startrightCoord
                        $starttopCoord = $starttopCoord+($currentRow*$cellheight)+(4.25*$currentRow)
                        $startbottomCoord = $startbottomCoord+($currentRow*$cellheight)+(4.25*$currentRow)
                     }
                }


            "Curent column is " + $currentColumn
            "Row count is " + $currentRow

            #save cellshot
            $cellBounds = [Drawing.Rectangle]::FromLTRB($startleftCoord,$starttopCoord, $startrightCoord, $startbottomCoord)
            $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++
            $firstiterationcomplete = 1
            "Saved CELLSHOT to $FilePath."
       }

Aucun commentaire:

Enregistrer un commentaire