Table of Contents

Class BitMatrix

Namespace
ZXing.Common
Assembly
zxing.dll

Represents a 2D matrix of bits. In function arguments below, and throughout the common module, x is the column position, and y is the row position. The ordering is always x, y. The origin is at the top-left.

Internally the bits are represented in a 1-D array of 32-bit ints. However, each row begins with a new int. This is done intentionally so that we can copy out a row into a BitArray very efficiently.

The ordering of bits is row-major. Within each int, the least significant bits are used first, meaning they represent lower x values. This is compatible with BitArray's implementation.

public sealed class BitMatrix
Inheritance
BitMatrix
Inherited Members

Constructors

BitMatrix(int)

Creates an empty square BitMatrix.

public BitMatrix(int dimension)

Parameters

dimension int

height and width

BitMatrix(int, int)

Creates an empty square BitMatrix.

public BitMatrix(int width, int height)

Parameters

width int

bit matrix width

height int

bit matrix height

Properties

Dimension

This method is for compatibility with older code. It's only logical to call if the matrix is square, so I'm throwing if that's not the case.

public int Dimension { get; }

Property Value

int

row/column dimension of this matrix

Height

public int Height { get; }

Property Value

int

The height of the matrix

this[int, int]

Gets the requested bit, where true means black.

public bool this[int x, int y] { get; set; }

Parameters

x int

The horizontal component (i.e. which column)

y int

The vertical component (i.e. which row)

Property Value

bool

value of given bit in matrix

RowSize

public int RowSize { get; }

Property Value

int

The rowsize of the matrix

Width

public int Width { get; }

Property Value

int

The width of the matrix

Methods

Clone()

Clones this instance.

public object Clone()

Returns

object

Equals(object)

Determines whether the specified object is equal to this instance.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with this instance.

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

GetHashCode()

Returns a hash code for this instance.

public override int GetHashCode()

Returns

int

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

ToString()

Returns a string that represents this instance.

public override string ToString()

Returns

string

A string that represents this instance.

ToString(string, string)

Returns a string that represents this instance.

public string ToString(string setString, string unsetString)

Parameters

setString string

The set string.

unsetString string

The unset string.

Returns

string

A string that represents this instance.

ToString(string, string, string)

Returns a string that represents this instance.

public string ToString(string setString, string unsetString, string lineSeparator)

Parameters

setString string

The set string.

unsetString string

The unset string.

lineSeparator string

The line separator.

Returns

string

A string that represents this instance.

clear()

Clears all bits (sets to false).

public void clear()

flip()

Flips every bit in the matrix.

public void flip()

flip(int, int)

Flips the given bit.

public void flip(int x, int y)

Parameters

x int

The horizontal component (i.e. which column)

y int

The vertical component (i.e. which row)

flipWhen(Func<int, int, bool>)

flip all of the bits, if shouldBeFlipped is true for the coordinates

public void flipWhen(Func<int, int, bool> shouldBeFlipped)

Parameters

shouldBeFlipped Func<int, int, bool>

should return true, if the bit at a given coordinate should be flipped

getBottomRightOnBit()

bottom right

public int[] getBottomRightOnBit()

Returns

int[]

getEnclosingRectangle()

This is useful in detecting the enclosing rectangle of a 'pure' barcode.

public int[] getEnclosingRectangle()

Returns

int[]

{left,top,width,height} enclosing rectangle of all 1 bits, or null if it is all white

getRow(int, BitArray)

A fast method to retrieve one row of data from the matrix as a BitArray.

public BitArray getRow(int y, BitArray row)

Parameters

y int

The row to retrieve

row BitArray

An optional caller-allocated BitArray, will be allocated if null or too small

Returns

BitArray

The resulting BitArray - this reference should always be used even when passing your own row

getTopLeftOnBit()

This is useful in detecting a corner of a 'pure' barcode.

public int[] getTopLeftOnBit()

Returns

int[]

{x,y} coordinate of top-left-most 1 bit, or null if it is all white

parse(bool[][])

Interprets a 2D array of booleans as a BitMatrix, where "true" means an "on" bit.

public static BitMatrix parse(bool[][] image)

Parameters

image bool[][]

bits of the image, as a row-major 2D array. Elements are arrays representing rows

Returns

BitMatrix

BitMatrix representation of image

parse(string, string, string)

parse the string representation to a bitmatrix

public static BitMatrix parse(string stringRepresentation, string setString, string unsetString)

Parameters

stringRepresentation string
setString string
unsetString string

Returns

BitMatrix

rotate(int)

Modifies this {@code BitMatrix} to represent the same but rotated the given degrees(0, 90, 180, 270)

public void rotate(int degrees)

Parameters

degrees int

number of degrees to rotate through counter-clockwise(0, 90, 180, 270)

Exceptions

ArgumentException

rotate180()

Modifies this {@code BitMatrix} to represent the same but rotated 180 degrees

public void rotate180()

rotate90()

Modifies this {@code BitMatrix} to represent the same but rotated 90 degrees counterclockwise

public void rotate90()

setRegion(int, int, int, int)

Sets a square region of the bit matrix to true.

public void setRegion(int left, int top, int width, int height)

Parameters

left int

The horizontal position to begin at (inclusive)

top int

The vertical position to begin at (inclusive)

width int

The width of the region

height int

The height of the region

setRow(int, BitArray)

Sets the row.

public void setRow(int y, BitArray row)

Parameters

y int

row to set

row BitArray

{@link BitArray} to copy from

xor(BitMatrix)

Exclusive-or (XOR): Flip the bit in this {@code BitMatrix} if the corresponding mask bit is set.

public void xor(BitMatrix mask)

Parameters

mask BitMatrix

The mask.