C# 自动裁剪图像
我有一个黑白 System.Drawing.Bitmap
我需要自动裁剪它,以便它只有适合图像所需的大小。该图像始终从左上角 (0,0) 位置开始,但我不确定需要多少高度和宽度。有什么办法可以自动裁剪到合适的尺寸吗?
I have a black and white System.Drawing.Bitmap
I need to auto-crop it so that it is only as big as needed to fit the image. This image always starts at the top left (0,0) position but I'm not sure how much height and width is will require. If there any way to auto-crop it to size?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是我使用的代码:
The following is the code I used:
如果您的图像不像我的那样从 0,0 开始,这里有一个变体,可以让您获得自动裁剪范围:
注意:如果您正在处理任何数量或高分辨率的图像,那么您需要研究一下比
GetPixel
方法更快的替代方法。If your image does not start at 0,0 like mine, here is a variant that gets you the auto-crop bounds:
Note: if you are processing any amount of images in quantity or high-resolution then you'll want to look into faster alternatives than the
GetPixel
method.