【发布时间】:2018-07-19 02:48:35
【问题描述】:
我有一个位图图像,我正在尝试克隆如下:
Bitmap bmpCrop = bmp.Clone(new System.Drawing.Rectangle(left, top, right - left + 1, bottom - top), bmp.PixelFormat);
有时此行会引发 OutOfMemoryException 类型的异常,因此在克隆之前我想确保 Rectangle 中指定的坐标不在位图范围之外,因为据我所知,Clone() 也可能会抛出一个内存不足异常。
我知道我可以通过以下方式获得图像的边界:
GraphicsUnit units = GraphicsUnit.Point;
RectangleF bmpRectangleF = bmp.GetBounds(ref units);
但是我不知道如何与 Rectanble bounds 进行比较。
有什么办法吗?
【问题讨论】:
-
bmpRectangleF.Contains() 可以测试。
标签: c# bitmap system.drawing