[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Make an improved diagonal picture montage in C#

[Make an improved diagonal picture montage in C#]

My earlier example Make a Pinterest-style diagonal picture montage in C# showed how you could make a picture montage showing parts of images rotated by a desired angle. While using that program today I found a small bug. The areas between the images are not always completely filled with the divider color.

The following picture shows the program displaying a picture montage that it created. The red circles show places where pieces of images show between the cells' borders.

[Make an improved diagonal picture montage in C#]

[Make an improved diagonal picture montage in C#]

The picture on the right shows aa closeup of one of the problem areas.

Fortunately the solution to this problem is simple. The Cell class's Draw method draws a cell's picture and border. The following code shows the part of that method that draws the border. The new statement highlighted in blue fixes the problem.

// Draw the cell. public void Draw(Graphics gr, Pen pen, float cell_width, float cell_height) { // Draw the cell's picture. ... // Outline the cell. gr.DrawRectangle(pen, Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height); GraphicsPath path = MakeRoundedRect(Bounds, 2 * pen.Width, 2 * pen.Width, true, true, true, true); gr.DrawPath(pen, path); }

The new statement draws a rectangle around the image before the code draws the image's rounded rectangle. The new rectangle fills in the problem areas where the rounded rectangles' corners don't quite meet the adjacent rectangles.

See the previous post for more details about how the program works.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.