Prerequisites:
- Inkscape
- MSPaint
- Visual Studio
First, we'll create the background (you can skip this section and just download StampBrush.png):
- Open Inkscape.
- Key F4 to select the Rectangle tool and create a rectangle roughly the same size as the document.
- Bring up the Fill and Stroke window (Ctrl-Shift-F).
- Under the 'Fill' tab, click the 'Flat Color' button and enter a value of 170 for R.
- File -> Properties -> Resize page to Content.
- Key F1 to select the Selector tool, and select the rectangle drawing.
- Ensure the drawing is zoomed to 100% (bottom right corner of screen).
- Filters -> Overlays -> Rubber Stamp.
- Take a screenshot (Alt-PrntScrn).
- Open MSPaint, and paste the screenshot onto the canvas.
- Move and crop the image so that only the textured effect is visible on the canvas.
- Save the image as StampBrush.png.
- Open Visual Studio and create a new WPF project.
- Copy StampBrush.png into your project.
- Open MainWindow.xaml, and copy the following attribute into the Window element:
xmlns:system="clr-namespace:System;assembly=mscorlib"
- replace the Grid element with the below XAML:
<Viewbox>
<Canvas Width="250" Height="320">
<Canvas.Resources>
<ImageBrush x:Key="stampBrush" ImageSource="StampBrush.png" Stretch="None" />
<system:String x:Key="StampText">SAMPLE</system:String>
</Canvas.Resources>
<WrapPanel Canvas.Top="0" Canvas.Left="70">
<WrapPanel.RenderTransform>
<RotateTransform CenterX="0" CenterY="0" Angle="45"></RotateTransform>
</WrapPanel.RenderTransform>
<Border BorderBrush="{StaticResource stampBrush}" BorderThickness="6" Margin="10" Padding="10,0,10,0" CornerRadius="3">
<TextBlock Foreground="{StaticResource ResourceKey=stampBrush}" FontSize="72" FontWeight="Bold" Text="{StaticResource StampText}"></TextBlock>
</Border>
</WrapPanel>
</Canvas>
</Viewbox>
That's it! Hit F5 and you'll have a window with a stamp in it. From here you can copy the Viewbox into a UserControl or make it a resource for use in your apps.
If you wish, you can reduce the size of the bitmap by opening StampBrush.png in MSPaint and cropping it down to the actual size of your stamp.
Of course, you can skip all the above steps and just download the demo project.

No comments:
Post a Comment