How do I tile and overlay images in WPF?

Posted by imnlfn on Stack Overflow See other posts from Stack Overflow or by imnlfn
Published on 2009-08-31T21:51:07Z Indexed on 2010/04/21 21:03 UTC
Read the original article Hit count: 148

Filed under:
|
|
|

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

  1. someone could point me towards a means of accomplishing the overlays and
  2. someone could indicate whether this is the best way to do the tiling.

Thanks!!

© Stack Overflow or respective owner

Related posts about wpf

Related posts about image