本文整理匯總了Java中com.google.zxing.common.BitMatrix.getTopLeftOnBit方法的典型用法代碼示例。如果您正苦於以下問題:Java BitMatrix.getTopLeftOnBit方法的具體用法?Java BitMatrix.getTopLeftOnBit怎麽用?Java BitMatrix.getTopLeftOnBit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.zxing.common.BitMatrix
的用法示例。
在下文中一共展示了BitMatrix.getTopLeftOnBit方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: extractPureBits
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {
int[] leftTopBlack = image.getTopLeftOnBit();
int[] rightBottomBlack = image.getBottomRightOnBit();
if (leftTopBlack == null || rightBottomBlack == null) {
throw NotFoundException.getNotFoundInstance();
}
int moduleSize = moduleSize(leftTopBlack, image);
int top = leftTopBlack[1];
int bottom = rightBottomBlack[1];
int left = leftTopBlack[0];
int matrixWidth = ((rightBottomBlack[0] - left) + 1) / moduleSize;
int matrixHeight = ((bottom - top) + 1) / moduleSize;
if (matrixWidth <= 0 || matrixHeight <= 0) {
throw NotFoundException.getNotFoundInstance();
}
int nudge = moduleSize / 2;
top += nudge;
left += nudge;
BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
for (int y = 0; y < matrixHeight; y++) {
int iOffset = top + (y * moduleSize);
for (int x = 0; x < matrixWidth; x++) {
if (image.get((x * moduleSize) + left, iOffset)) {
bits.set(x, y);
}
}
}
return bits;
}
示例2: extractPureBits
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
/**
* This method detects a code in a "pure" image -- that is, pure monochrome image
* which contains only an unrotated, unskewed, image of a code, with some white border
* around it. This is a specialized method that works exceptionally fast in this special
* case.
*
* @see com.google.zxing.qrcode.QRCodeReader#extractPureBits(BitMatrix)
*/
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {
int[] leftTopBlack = image.getTopLeftOnBit();
int[] rightBottomBlack = image.getBottomRightOnBit();
if (leftTopBlack == null || rightBottomBlack == null) {
throw NotFoundException.getNotFoundInstance();
}
int moduleSize = moduleSize(leftTopBlack, image);
int top = leftTopBlack[1];
int bottom = rightBottomBlack[1];
int left = leftTopBlack[0];
int right = rightBottomBlack[0];
int matrixWidth = (right - left + 1) / moduleSize;
int matrixHeight = (bottom - top + 1) / moduleSize;
if (matrixWidth <= 0 || matrixHeight <= 0) {
throw NotFoundException.getNotFoundInstance();
}
// Push in the "border" by half the module width so that we start
// sampling in the middle of the module. Just in case the image is a
// little off, this will help recover.
int nudge = moduleSize / 2;
top += nudge;
left += nudge;
// Now just read off the bits
BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
for (int y = 0; y < matrixHeight; y++) {
int iOffset = top + y * moduleSize;
for (int x = 0; x < matrixWidth; x++) {
if (image.get(left + x * moduleSize, iOffset)) {
bits.set(x, y);
}
}
}
return bits;
}
示例3: extractPureBits
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {
int[] leftTopBlack = image.getTopLeftOnBit();
int[] rightBottomBlack = image.getBottomRightOnBit();
if (leftTopBlack == null || rightBottomBlack == null) {
throw NotFoundException.getNotFoundInstance();
}
float moduleSize = moduleSize(leftTopBlack, image);
int top = leftTopBlack[1];
int bottom = rightBottomBlack[1];
int left = leftTopBlack[0];
int right = rightBottomBlack[0];
if (left >= right || top >= bottom) {
throw NotFoundException.getNotFoundInstance();
}
if (bottom - top != right - left) {
right = left + (bottom - top);
}
int matrixWidth = Math.round(((float) ((right - left) + 1)) / moduleSize);
int matrixHeight = Math.round(((float) ((bottom - top) + 1)) / moduleSize);
if (matrixWidth <= 0 || matrixHeight <= 0) {
throw NotFoundException.getNotFoundInstance();
} else if (matrixHeight != matrixWidth) {
throw NotFoundException.getNotFoundInstance();
} else {
int nudge = (int) (moduleSize / 2.0f);
top += nudge;
left += nudge;
int nudgedTooFarRight = (((int) (((float) (matrixWidth - 1)) * moduleSize)) + left) -
right;
if (nudgedTooFarRight > 0) {
if (nudgedTooFarRight > nudge) {
throw NotFoundException.getNotFoundInstance();
}
left -= nudgedTooFarRight;
}
int nudgedTooFarDown = (((int) (((float) (matrixHeight - 1)) * moduleSize)) + top) -
bottom;
if (nudgedTooFarDown > 0) {
if (nudgedTooFarDown > nudge) {
throw NotFoundException.getNotFoundInstance();
}
top -= nudgedTooFarDown;
}
BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
for (int y = 0; y < matrixHeight; y++) {
int iOffset = top + ((int) (((float) y) * moduleSize));
for (int x = 0; x < matrixWidth; x++) {
if (image.get(((int) (((float) x) * moduleSize)) + left, iOffset)) {
bits.set(x, y);
}
}
}
return bits;
}
}