How do I tile and overlay images in WPF?
- by imnlfn
I'm very new to WPF and trying to port an application from VB6 to C# and XAML.
What I need to do now is create one big image out of a number of small ones, arranged like a series of "tiles." Some of these smaller ones will have overlays superimposed on them.
In VB6, accomplishing both the tiling and overlaying would simply be a matter of using the PaintPicture method with the PictureBox control.
This is my attempt at the tiling and overlaying in one step (though really the overlaying could occur beforehand):
ImageDrawing Drawing1 = new ImageDrawing(new BitmapImage(new Uri(@"c:\one.bmp",
UriKind.Absolute)),
new Rect(0, 0, 40, 130));
ImageDrawing Drawing2 = new ImageDrawing(new BitmapImage(new Uri(@"c:\two.bmp",
UriKind.Absolute)),
new Rect(40, 0, 45, 130));
ImageDrawing Drawing3 = new ImageDrawing(new BitmapImage(new Uri(@"c:\overlay.bmp",
UriKind.Absolute)),
new Rect(40, 0, 45, 130));
DrawingGroup myDrawingGroup = new DrawingGroup();
myDrawingGroup.Children.Add(Drawing1);
myDrawingGroup.Children.Add(Drawing2);
myDrawingGroup.Children.Add(Drawing3);
myImage.Source = new DrawingImage(myDrawingGroup);
The tiling works fine, but the overlay is a no-go. I was wondering if
someone could point me towards a means of accomplishing the overlays and
someone could indicate whether this is the best way to do the tiling.
Thanks!!