本文整理匯總了Java中com.google.zxing.common.BitMatrix.getHeight方法的典型用法代碼示例。如果您正苦於以下問題:Java BitMatrix.getHeight方法的具體用法?Java BitMatrix.getHeight怎麽用?Java BitMatrix.getHeight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.zxing.common.BitMatrix
的用法示例。
在下文中一共展示了BitMatrix.getHeight方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createQRCode
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
public static Bitmap createQRCode(String str,int widthAndHeight) throws WriterException {
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix matrix = new MultiFormatWriter().encode(str,
BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (matrix.get(x, y)) {
pixels[y * width + x] = BLACK;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
示例2: createQRCode
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
public static Bitmap createQRCode(String str, int widthAndHeight) throws WriterException {
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix matrix = new MultiFormatWriter().encode(str,
BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (matrix.get(x, y)) {
pixels[y * width + x] = BLACK;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
示例3: createQRCode
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
public static Bitmap createQRCode(String str,int widthAndHeight) throws WriterException {
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix matrix = new MultiFormatWriter().encode(str,
BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (matrix.get(x, y)) {
pixels[y * width + x] = BLACK;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
示例4: createImage
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
private static BufferedImage createImage(String content, String imgPath,
boolean needCompress) throws Exception {
Hashtable hints = new Hashtable();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix bitMatrix = new MultiFormatWriter().encode(content,
BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000
: 0xFFFFFFFF);
}
}
if (imgPath == null || "".equals(imgPath)) {
return image;
}
// 插入圖片
CodeUtil.insertImage(image, imgPath, needCompress);
return image;
}
示例5: create
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
public static @NonNull Bitmap create(String data) {
try {
BitMatrix result = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, 512, 512);
Bitmap bitmap = Bitmap.createBitmap(result.getWidth(), result.getHeight(), Bitmap.Config.ARGB_8888);
for (int y = 0; y < result.getHeight(); y++) {
for (int x = 0; x < result.getWidth(); x++) {
if (result.get(x, y)) {
bitmap.setPixel(x, y, Color.BLACK);
}
}
}
return bitmap;
} catch (WriterException e) {
Log.w(TAG, e);
return Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888);
}
}
示例6: createQrCode
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
@Nullable
static Bitmap createQrCode(DisplayMetrics dm, String input) {
int smallestDimen = Math.min(dm.widthPixels, dm.heightPixels);
try {
// Generate QR code
final BitMatrix encoded = new QRCodeWriter().encode(
input, QR_CODE, smallestDimen, smallestDimen);
// Convert QR code to Bitmap
int width = encoded.getWidth();
int height = encoded.getHeight();
int[] pixels = new int[width * height];
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
pixels[y * width + x] = encoded.get(x, y) ? BLACK : WHITE;
}
}
Bitmap qr = Bitmap.createBitmap(width, height, ARGB_8888);
qr.setPixels(pixels, 0, width, 0, 0, width, height);
return qr;
} catch (WriterException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
return null;
}
}
示例7: encodeAsBitmap
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
static Bitmap encodeAsBitmap(String contents, BarcodeFormat format,
int desiredWidth, int desiredHeight) throws WriterException {
Hashtable<EncodeHintType, Object> hints = null;
String encoding = guessAppropriateEncoding(contents);
if (encoding != null) {
hints = new Hashtable<EncodeHintType, Object>(2);
hints.put(EncodeHintType.CHARACTER_SET, encoding);
}
MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix result = writer.encode(contents, format, desiredWidth,
desiredHeight, hints);
int width = result.getWidth();
int height = result.getHeight();
int[] pixels = new int[width * height];
// All are 0, or black, by default
for (int y = 0; y < height; y++) {
int offset = y * width;
for (int x = 0; x < width; x++) {
pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
示例8: buildImage
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
private Image buildImage(BarcodeFormat format,String data,int w,int h){
try{
Map<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.MARGIN,0);
if(format.equals(BarcodeFormat.QR_CODE)){
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
}
BitMatrix matrix = new MultiFormatWriter().encode(data,format, w, h,hints);
int width = matrix.getWidth();
int height = matrix.getHeight();
BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_ARGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);
}
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(image, "png", outputStream);
byte[] bytes=outputStream.toByteArray();
String base64Data=Base64Utils.encodeToString(bytes);
IOUtils.closeQuietly(outputStream);
return new Image(base64Data,w,h);
}catch(Exception ex){
throw new ReportComputeException(ex);
}
}
示例9: create
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
/**
* Create and return your Image here.
* NOTE: make sure, your class is public and has a public default constructor!
*
* @param tag The dialog-fragments tag
* @param extras The extras supplied to {@link SimpleImageDialog#extra(Bundle)}
* @return the image to be shown
*/
@Override
public Bitmap create(@Nullable String tag, @NonNull Bundle extras) {
String content = extras.getString(QR_CONTENT);
if (content == null) return null;
// Generate
try {
EnumMap<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q);
hints.put(EncodeHintType.CHARACTER_SET, "UTF8");
BitMatrix bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE,
1024, 1024, hints);
int width = bitMatrix.getWidth(), height = bitMatrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
pixels[y*width + x] = bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE;
}
}
Bitmap qr = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
qr.setPixels(pixels, 0, width, 0, 0, width, height);
return qr;
} catch (WriterException ignored) {}
return null;
}
示例10: BitMatrixParser
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
BitMatrixParser(BitMatrix bitMatrix) throws FormatException {
int dimension = bitMatrix.getHeight();
if (dimension < 21 || (dimension & 3) != 1) {
throw FormatException.getFormatInstance();
}
this.bitMatrix = bitMatrix;
}
示例11: BitMatrixParser
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
BitMatrixParser(BitMatrix bitMatrix) throws FormatException {
int dimension = bitMatrix.getHeight();
if (dimension < 8 || dimension > 144 || (dimension & 1) != 0) {
throw FormatException.getFormatInstance();
}
this.version = readVersion(bitMatrix);
this.mappingBitMatrix = extractDataRegion(bitMatrix);
this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.getWidth(), this
.mappingBitMatrix.getHeight());
}
示例12: WhiteRectangleDetector
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
public WhiteRectangleDetector(BitMatrix image) throws NotFoundException {
this(image, 10, image.getWidth() / 2, image.getHeight() / 2);
}
示例13: createQRCodeWithLogo
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
/**
* 生成帶Logo的二維碼
*
* @param content 二維碼內容
* @param size 二維碼內容大小
* @param bitmap 二維碼Logo
* @param color 二維碼顏色
*/
public static Bitmap createQRCodeWithLogo(String content, int size, Bitmap bitmap, int color) {
try {
int logoHalfWidth = size / 10;
Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, CHARACTER_SET);
// 設置容錯級別,默認為ErrorCorrectionLevel.L
// 因為中間加入logo所以建議你把容錯級別調至H,否則可能會出現識別不了
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.MARGIN, 2); // default is 4
// hints.put(EncodeHintType.MAX_SIZE, 350);
// hints.put(EncodeHintType.MIN_SIZE, 100);
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, size, size, hints);
// 將logo圖片按martix設置的信息縮放
bitmap = Bitmap.createScaledBitmap(bitmap, size, size, false);
int width = bitMatrix.getWidth(); // 矩陣高度
int height = bitMatrix.getHeight(); // 矩陣寬度
int halfW = width / 2;
int halfH = height / 2;
Matrix matrix = new Matrix();
float sx = (float) 2 * logoHalfWidth / bitmap.getWidth();
float sy = (float) 2 * logoHalfWidth / bitmap.getHeight();
matrix.setScale(sx, sy);
// 設置縮放信息
// 將logo圖片按martix設置的信息縮放
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
int[] pixels = new int[size * size];
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
if (x > halfW - logoHalfWidth
&& x < halfW + logoHalfWidth
&& y > halfH - logoHalfWidth
&& y < halfH + logoHalfWidth) {
//該位置用於存放圖片信息
//記錄圖片每個像素信息
pixels[y * width + x] = bitmap.getPixel(x - halfW + logoHalfWidth, y - halfH + logoHalfWidth);
} else {
if (bitMatrix.get(x, y)) {
pixels[y * size + x] = color;
} else {
pixels[y * size + x] = WHITE;
}
}
}
}
Bitmap result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
// 通過像素數組生成bitmap
result.setPixels(pixels, 0, size, 0, 0, size, size);
return result;
} catch (WriterException e) {
return null;
}
}
示例14: crossCheckVertical
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
private float crossCheckVertical(int startI, int centerJ, int maxCount, int
originalStateCountTotal) {
BitMatrix image = this.image;
int maxI = image.getHeight();
int[] stateCount = this.crossCheckStateCount;
stateCount[0] = 0;
stateCount[1] = 0;
stateCount[2] = 0;
int i = startI;
while (i >= 0 && image.get(centerJ, i) && stateCount[1] <= maxCount) {
stateCount[1] = stateCount[1] + 1;
i--;
}
if (i < 0 || stateCount[1] > maxCount) {
return Float.NaN;
}
while (i >= 0 && !image.get(centerJ, i) && stateCount[0] <= maxCount) {
stateCount[0] = stateCount[0] + 1;
i--;
}
if (stateCount[0] > maxCount) {
return Float.NaN;
}
i = startI + 1;
while (i < maxI && image.get(centerJ, i) && stateCount[1] <= maxCount) {
stateCount[1] = stateCount[1] + 1;
i++;
}
if (i == maxI || stateCount[1] > maxCount) {
return Float.NaN;
}
while (i < maxI && !image.get(centerJ, i) && stateCount[2] <= maxCount) {
stateCount[2] = stateCount[2] + 1;
i++;
}
if (stateCount[2] > maxCount || Math.abs(((stateCount[0] + stateCount[1]) +
stateCount[2]) - originalStateCountTotal) * 5 >= originalStateCountTotal * 2 ||
!foundPatternCross(stateCount)) {
return Float.NaN;
}
return centerFromEnd(stateCount, i);
}
示例15: crossCheckVertical
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
/**
* <p>After a horizontal scan finds a potential alignment pattern, this method
* "cross-checks" by scanning down vertically through the center of the possible
* alignment pattern to see if the same proportion is detected.</p>
*
* @param startI row where an alignment pattern was detected
* @param centerJ center of the section that appears to cross an alignment pattern
* @param maxCount maximum reasonable number of modules that should be
* observed in any reading state, based on the results of the horizontal scan
* @return vertical center of alignment pattern, or {@link Float#NaN} if not found
*/
private float crossCheckVertical(int startI, int centerJ, int maxCount,
int originalStateCountTotal) {
BitMatrix image = this.image;
int maxI = image.getHeight();
int[] stateCount = crossCheckStateCount;
stateCount[0] = 0;
stateCount[1] = 0;
stateCount[2] = 0;
// Start counting up from center
int i = startI;
while (i >= 0 && image.get(centerJ, i) && stateCount[1] <= maxCount) {
stateCount[1]++;
i--;
}
// If already too many modules in this state or ran off the edge:
if (i < 0 || stateCount[1] > maxCount) {
return Float.NaN;
}
while (i >= 0 && !image.get(centerJ, i) && stateCount[0] <= maxCount) {
stateCount[0]++;
i--;
}
if (stateCount[0] > maxCount) {
return Float.NaN;
}
// Now also count down from center
i = startI + 1;
while (i < maxI && image.get(centerJ, i) && stateCount[1] <= maxCount) {
stateCount[1]++;
i++;
}
if (i == maxI || stateCount[1] > maxCount) {
return Float.NaN;
}
while (i < maxI && !image.get(centerJ, i) && stateCount[2] <= maxCount) {
stateCount[2]++;
i++;
}
if (stateCount[2] > maxCount) {
return Float.NaN;
}
int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) {
return Float.NaN;
}
return foundPatternCross(stateCount) ? centerFromEnd(stateCount, i) : Float.NaN;
}