下面列出了com.google.zxing.common.BitMatrix#clear ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static BitMatrix updateBit(BitMatrix matrix, int margin){
int tempM = margin*2;
int[] rec = matrix.getEnclosingRectangle(); //获取二维码图案的属性
int resWidth = rec[2] + tempM;
int resHeight = rec[3] + tempM;
BitMatrix resMatrix = new BitMatrix(resWidth, resHeight); // 按照自定义边框生成新的BitMatrix
resMatrix.clear();
for(int i= margin; i < resWidth- margin; i++){ //循环,将二维码图案绘制到新的bitMatrix中
for(int j=margin; j < resHeight-margin; j++){
if(matrix.get(i-margin + rec[0], j-margin + rec[1])){
resMatrix.set(i,j);
}
}
}
return resMatrix;
}
private static BitMatrix bitMatrixFrombitArray(byte[][] input) {
BitMatrix output = new BitMatrix(input[0].length + 60, input.length + 60);
output.clear();
int y = 0;
int yOutput = output.getHeight() - 30;
while (y < input.length) {
for (int x = 0; x < input[0].length; x++) {
if (input[y][x] == (byte) 1) {
output.set(x + 30, yOutput);
}
}
y++;
yOutput--;
}
return output;
}
/**
* Convert the ByteMatrix to BitMatrix.
*
* @param matrix The input matrix.
* @return The output matrix.
*/
private static BitMatrix convertByteMatrixToBitMatrix(ByteMatrix matrix) {
int matrixWidgth = matrix.getWidth();
int matrixHeight = matrix.getHeight();
BitMatrix output = new BitMatrix(matrixWidgth, matrixHeight);
output.clear();
for (int i = 0; i < matrixWidgth; i++) {
for (int j = 0; j < matrixHeight; j++) {
// Zero is white in the bytematrix
if (matrix.get(i, j) == 1) {
output.set(i, j);
}
}
}
return output;
}
/**
* Convert the ByteMatrix to BitMatrix.
*
* @param matrix The input matrix.
* @return The output matrix.
*/
private static BitMatrix convertByteMatrixToBitMatrix(ByteMatrix matrix) {
int matrixWidgth = matrix.getWidth();
int matrixHeight = matrix.getHeight();
BitMatrix output = new BitMatrix(matrixWidgth, matrixHeight);
output.clear();
for (int i = 0; i < matrixWidgth; i++) {
for (int j = 0; j < matrixHeight; j++) {
// Zero is white in the bytematrix
if (matrix.get(i, j) == 1) {
output.set(i, j);
}
}
}
return output;
}
/**
* Convert the ByteMatrix to BitMatrix.
*
* @param matrix The input matrix.
* @return The output matrix.
*/
private static BitMatrix convertByteMatrixToBitMatrix(ByteMatrix matrix) {
int matrixWidgth = matrix.getWidth();
int matrixHeight = matrix.getHeight();
BitMatrix output = new BitMatrix(matrixWidgth, matrixHeight);
output.clear();
for (int i = 0; i < matrixWidgth; i++) {
for (int j = 0; j < matrixHeight; j++) {
// Zero is white in the bytematrix
if (matrix.get(i, j) == 1) {
output.set(i, j);
}
}
}
return output;
}
/**
* Convert the ByteMatrix to BitMatrix.
*
* @param matrix The input matrix.
* @return The output matrix.
*/
private static BitMatrix convertByteMatrixToBitMatrix(ByteMatrix matrix) {
int matrixWidgth = matrix.getWidth();
int matrixHeight = matrix.getHeight();
BitMatrix output = new BitMatrix(matrixWidgth, matrixHeight);
output.clear();
for (int i = 0; i < matrixWidgth; i++) {
for (int j = 0; j < matrixHeight; j++) {
// Zero is white in the bytematrix
if (matrix.get(i, j) == 1) {
output.set(i, j);
}
}
}
return output;
}
/**
* This takes an array holding the values of the PDF 417
*
* @param input a byte array of information with 0 is black, and 1 is white
* @return BitMatrix of the input
*/
private static BitMatrix bitMatrixFrombitArray(byte[][] input) {
// Creates a small whitespace border around the barcode
int whiteSpace = 30;
// Creates the bitmatrix with extra space for whitespace
BitMatrix output = new BitMatrix(input[0].length + 2 * whiteSpace, input.length + 2 * whiteSpace);
output.clear();
for (int y = 0, yOutput = output.getHeight() - whiteSpace; y < input.length; y++, yOutput--) {
for (int x = 0; x < input[0].length; x++) {
// Zero is white in the bytematrix
if (input[y][x] == 1) {
output.set(x + whiteSpace, yOutput);
}
}
}
return output;
}
private static BitMatrix a(byte abyte0[][])
{
BitMatrix bitmatrix = new BitMatrix(60 + abyte0.length, 60 + abyte0[0].length);
bitmatrix.clear();
for (int i = 0; i < abyte0.length; i++)
{
for (int j = 0; j < abyte0[0].length; j++)
{
if (abyte0[i][j] == 1)
{
bitmatrix.set(i + 30, j + 30);
}
}
}
return bitmatrix;
}
/**
* Convert the ByteMatrix to BitMatrix.
*
* @param matrix
* The input matrix.
* @return The output matrix.
*/
private static BitMatrix convertByteMatrixToBitMatrix(ByteMatrix matrix) {
int matrixWidgth = matrix.getWidth();
int matrixHeight = matrix.getHeight();
BitMatrix output = new BitMatrix(matrixWidgth, matrixHeight);
output.clear();
for (int i = 0; i < matrixWidgth; i++) {
for (int j = 0; j < matrixHeight; j++) {
// Zero is white in the bytematrix
if (matrix.get(i, j) == 1) {
output.set(i, j);
}
}
}
return output;
}
/**
* This takes an array holding the values of the PDF 417
*
* @param input a byte array of information with 0 is black, and 1 is white
* @param margin border around the barcode
* @return BitMatrix of the input
*/
private static BitMatrix bitMatrixFrombitArray(byte[][] input, int margin) {
// Creates the bitmatrix with extra space for whitespace
BitMatrix output = new BitMatrix(input[0].length + 2 * margin, input.length + 2 * margin);
output.clear();
for (int y = 0, yOutput = output.getHeight() - margin - 1; y < input.length; y++, yOutput--) {
for (int x = 0; x < input[0].length; x++) {
// Zero is white in the bytematrix
if (input[y][x] == 1) {
output.set(x + margin, yOutput);
}
}
}
return output;
}
/**
* This takes an array holding the values of the PDF 417
*
* @param input a byte array of information with 0 is black, and 1 is white
* @param margin border around the barcode
* @return BitMatrix of the input
*/
private static BitMatrix bitMatrixFrombitArray(byte[][] input, int margin) {
// Creates the bitmatrix with extra space for whitespace
BitMatrix output = new BitMatrix(input[0].length + 2 * margin, input.length + 2 * margin);
output.clear();
for (int y = 0, yOutput = output.getHeight() - margin - 1; y < input.length; y++, yOutput--) {
for (int x = 0; x < input[0].length; x++) {
// Zero is white in the bytematrix
if (input[y][x] == 1) {
output.set(x + margin, yOutput);
}
}
}
return output;
}
/**
* This takes an array holding the values of the PDF 417
*
* @param input a byte array of information with 0 is black, and 1 is white
* @param margin border around the barcode
* @return BitMatrix of the input
*/
private static BitMatrix bitMatrixFrombitArray(byte[][] input, int margin) {
// Creates the bitmatrix with extra space for whitespace
BitMatrix output = new BitMatrix(input[0].length + 2 * margin, input.length + 2 * margin);
output.clear();
for (int y = 0, yOutput = output.getHeight() - margin - 1; y < input.length; y++, yOutput--) {
for (int x = 0; x < input[0].length; x++) {
// Zero is white in the bytematrix
if (input[y][x] == 1) {
output.set(x + margin, yOutput);
}
}
}
return output;
}
/**
* This takes an array holding the values of the PDF 417
*
* @param input a byte array of information with 0 is black, and 1 is white
* @param margin border around the barcode
* @return BitMatrix of the input
*/
private static BitMatrix bitMatrixFrombitArray(byte[][] input, int margin) {
// Creates the bitmatrix with extra space for whitespace
BitMatrix output = new BitMatrix(input[0].length + 2 * margin, input.length + 2 * margin);
output.clear();
for (int y = 0, yOutput = output.getHeight() - margin - 1; y < input.length; y++, yOutput--) {
for (int x = 0; x < input[0].length; x++) {
// Zero is white in the bytematrix
if (input[y][x] == 1) {
output.set(x + margin, yOutput);
}
}
}
return output;
}