.net 检验这个,;这一切都是理论上的,但我想为您提供一个一般的想法或方法,然后只是链接到第三方库或组件

.net 检验这个,;这一切都是理论上的,但我想为您提供一个一般的想法或方法,然后只是链接到第三方库或组件,.net,drawing,gdi,.net,Drawing,Gdi,编辑: 下面是一个链接,它提供了一个与实际代码示例类似的方法。 我不相信GDI+中有任何东西,因为GDI+是一个底层平台,可以在上面构建trim等高级功能。我不相信GDI+中有任何东西,因为GDI+是一个底层平台,可以在上面构建trim等高级功能。确定什么是“空”空间=>这很难!确定什么是“空”空间=>这是困难的一点! int x = 0, y = 0; Rectangle rect = new Rectangle(); bool nonWhitePixelFound = false;

编辑:

  • 下面是一个链接,它提供了一个与实际代码示例类似的方法。

我不相信GDI+中有任何东西,因为GDI+是一个底层平台,可以在上面构建trim等高级功能。我不相信GDI+中有任何东西,因为GDI+是一个底层平台,可以在上面构建trim等高级功能。确定什么是“空”空间=>这很难!确定什么是“空”空间=>这是困难的一点!
int x = 0, y = 0;
Rectangle rect = new Rectangle();
bool nonWhitePixelFound = false;

for (int row = 0; row < image.Bounds.Height; row++) {
    if (!nonWhitePixelFound) {
        for (int column = 0; column = image.Bounds.Width; column++) {
            if (pixel.getColor() != Color.White) {
                rect.Width++;
            }
            else {
                rightBoundPixelFound = true; // Okay, we encountered a non-white pixel
                                             // so we know we cannot trim anymore to the right
                rect.Height--; // Since we don't want to clip the row with the non-white pixel
                nonWhitePixelFound = true;
                return rect; // I did not wrap this code in a function body in this example,
                             // but to break both loops you should return, or this would be 
                             // a rare case to use goto
            }
        }
    }
    rect.Height++; // Since we have not found a non-white pixel yet, and went through the
                   // entire row if pixels, we can go ahead and check the next row
}