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?

有帮助吗?

解决方案

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. :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top