Safe resize / and crop with aspect ratio keeping. #2790
-
I am writing a software to easily resize and crop image to a specific resolution. I managed to do the GUI in a Winform app but I struggle to do the resize and crop. What I would like is to give a rectangle where any corner can be outside the image (meaning x or y can be < 0 or x >= width or y >= height) without having an exception. It would be even better if I can easily specify the color to use to fill the empty space. For the record Crop and Resize but did not manage to do this. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @codec-abc Yes you should be able to do this with the Resize Options. https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Processing.ResizeOptions.html?q=ResizeOptions I would first crop using an intersection of the image bounds and the crop rectangle, you can then do a resize using the pad mode and set a pad color. |
Beta Was this translation helpful? Give feedback.
-
@JimBobSquarePants Works like a charm. You probably saved me a few hours of toying around. Thanks! |
Beta Was this translation helpful? Give feedback.
Hi @codec-abc
Yes you should be able to do this with the Resize Options. https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Processing.ResizeOptions.html?q=ResizeOptions
I would first crop using an intersection of the image bounds and the crop rectangle, you can then do a resize using the pad mode and set a pad color.