private static int GetNonTransparentRow(Bitmap bitmap, bool topToBottom) { int column = 0; int row = topToBottom ? 0 : bitmap.Height - 1; int increment = topToBottom ? 1 : -1; int limit = topToBottom ? bitmap.Height : 0; while ((row != limit) && bitmap.IsTransparent(column, row)) { while ((column < bitmap.Width) && bitmap.IsTransparent(column, row)) { ++column; } if (column == bitmap.Width) { column = 0; row += increment; } } return row; }
private static int GetNonTransparentColumn(Bitmap bitmap, bool leftToRight) { int column = leftToRight ? 0 : bitmap.Width - 1; int row = 0; int increment = leftToRight ? 1 : -1; int limit = leftToRight ? bitmap.Width : 0; while ((column != limit) && bitmap.IsTransparent(column, row)) { while ((row < bitmap.Height) && bitmap.IsTransparent(column, row)) { ++row; } if (row == bitmap.Height) { row = 0; column += increment; } } return column; }