Вопрос

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