This script starts with my previous blog on Mosaic Style Images but adds a ‘clear’ image in the center which appears to be framed by the pattern. You control the size the center image as well as all the properties from the Mosaic Images script.
 
Here are a couple examples. First is one framed by FilledCurves at about 80% of the image.
 
MosaicFramedCurves_20140702_164104
 
This one is FilledRectangles sized at 80% with a Border.
 
MosaicFramedSquares_20140702_164704
 
And this one is a few FilledPolygons with a transparent background with a Border.
 
MosaicFramedPolygons_20140702_165044
 
FilledCurves with a 20% center image and a Transparent Background without a Border.
 
MosaicFramedCurves_20140711_184044
 
The is another example with 80% sized FilledPolygons and a Transparent Background and a Border.
 
MosaicFramedPolygons_20140704_114839
 
Staring with the Mosaic Images script, I added an additional TrackBar to select the percentage of the final centered image relative to the starting image. Select 90% and you get a very thin frame, select 50% and it’s half and half.
 

# Size of Center Image TrackBar
$centerImageTrackBar = New-Object Windows.Forms.TrackBar
$centerImageTrackBar.Location = "160,160"
$centerImageTrackBar.Orientation = "Horizontal"
$centerImageTrackBar.Width = 325
$centerImageTrackBar.Height = 40
$centerImageTrackBar.LargeChange = 10
$centerImageTrackBar.SmallChange = 1
$centerImageTrackBar.TickFrequency = 10
$centerImageTrackBar.TickStyle = "TopLeft"
$centerImageTrackBar.SetRange(1, 100)
$centerImageTrackBar.Value = 80
$centerImageTrackBarValue = 80
$centerImageTrackBar.add_ValueChanged({
    $centerImageTrackBarValue = $centerImageTrackBar.Value
    $centerImageTrackBarLabel.Text = "Center Frame Size % ($centerImageTrackBarValue)"
    $global:reductionSize = $centerImageTrackBarValue
})
$mainForm.Controls.add($centerImageTrackBar)

# Size of Center Image TrackBar Label
$centerImageTrackBarLabel = New-Object System.Windows.Forms.Label 
$centerImageTrackBarLabel.Location = "15,160"
$centerImageTrackBarLabel.Size = "160,23"
$centerImageTrackBarLabel.ForeColor = "MediumBlue"
$centerImageTrackBarLabel.Text = "Center Frame Size % ($centerImageTrackBarValue)"
$mainForm.Controls.Add($centerImageTrackBarLabel)

 
After a Mosaic pattern has been drawn, as in Mosaic Image script, a final centered pattern is drawn at the size specified. Here is the FilledRectangle which is used in the Square, Rectangle and Polygon Patterns. The FilledEllipse is used in Ellipse and Curves Patterns. The final centered pattern size is the selected percentage of the original image size. The central pattern is centered from the upper left corner of the pattern by subtracting the pattern length and width from the original image size and dividing by 2.
 

    $reduction = $global:reductionSize*.01
    # Paint central image
    If ([int]$borderWidth -ge 1) {
        $bitmapGraphics.FillRectangle($brushBlack, `
            (([int]$image.width-($image.width*$reduction))/2)-$borderWidth, `
            (([int]$image.height-($image.height*$reduction))/2)-$borderWidth, `
            ($image.width*$reduction)+([int]$borderWidth*2), `
            ($image.height*$reduction)+([int]$borderWidth*2))
    }
    $bitmapGraphics.FillRectangle($brush, `
            (([int]$image.width-($image.width*$reduction))/2), `
            (([int]$image.height-($image.height*$reduction))/2), `
            $image.width*$reduction, `
            $image.height*$reduction)

 
MosaicFramedImages
 
Download the complete script here – MosaicFramedImages.ps1
 
 
(Thanks to my friend Kevin Bell for providing the simple centering formula while I was lost wondering around in overcomplexity land.)

Advertisements