Erwin Alva
Erwin Alva

Reputation: 393

Crop With Padding

I need to crop an image specifying coordinates that may exceed the image's bounds. If the coordinates are off, appropriate padding is applied.

Normally:

+===============+
| Source Bitmap |
|   +-------+   |
|   + Crop  +   |
|   +-------+   |
|               |
+===============+

...which works perfectly well with WriteableBitmapEx's Crop() extension. But in my case:

+-----------+
+ Crop      +
+           +
+ +===============+
+ | Source Bitmap |
+ |               |
+ +===============+
+           +
+-----------+

In this case, the bounds exceed the top, left, and bottom. The resulting bitmap need to be:

+-----------+
+           +
+           +
+ +=========+
+ |         + 
+ |         +
+ +=========+
+           +
+-----------+

What's the best (and fastest) way to accomplish this?

Upvotes: 0

Views: 280

Answers (1)

Rene Schulte
Rene Schulte

Reputation: 2962

The easiest would be to create a new WB with the dimension of the final result, then use the Blit() method to copy the region of the source to your new destination bitmap's region.

Nice ASCII art job btw. :)

Upvotes: 1

Related Questions