本文整理匯總了Java中com.google.zxing.common.BitMatrix.get方法的典型用法代碼示例。如果您正苦於以下問題:Java BitMatrix.get方法的具體用法?Java BitMatrix.get怎麽用?Java BitMatrix.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.zxing.common.BitMatrix
的用法示例。
在下文中一共展示了BitMatrix.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createNewQR
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
private Bitmap createNewQR(String s) {
MultiFormatWriter mFW = new MultiFormatWriter();
Bitmap bM = null;
int px = (int) GraphicUtils.dpToPx(250);
try {
BitMatrix bitM = mFW.encode(s, BarcodeFormat.QR_CODE, px, px);
bM = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
for (int i = 0; i < px; i++) {
for (int j = 0; j < px; j++) {
int c = (bitM.get(i, j)) ? Color.BLACK : Color.WHITE;
bM.setPixel(i, j, c);
}
}
} catch (WriterException e) {
Utils.logError(e);
}
return bM;
}
示例2: encodeAsBitmap
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
Bitmap encodeAsBitmap(String str) throws WriterException {
BitMatrix result;
try {
result = new MultiFormatWriter().encode(str,
BarcodeFormat.QR_CODE, WIDTH, WIDTH, null);
} catch (IllegalArgumentException iae) {
// Unsupported format
return null;
}
int w = result.getWidth();
int h = result.getHeight();
int[] pixels = new int[w * h];
for (int y = 0; y < h; y++) {
int offset = y * w;
for (int x = 0; x < w; x++) {
pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
}
}
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, w, 0, 0, w, h);
return bitmap;
}
示例3: syncEncodeQRCode
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
/**
* 同步創建指定前景色、指定背景色、帶logo的二維碼圖片。該方法是耗時操作,請在子線程中調用。
*
* @param content 要生成的二維碼圖片內容
* @param size 圖片寬高,單位為px
* @param foregroundColor 二維碼圖片的前景色
* @param backgroundColor 二維碼圖片的背景色
* @param logo 二維碼圖片的logo
*/
public static Bitmap syncEncodeQRCode(String content, int size, int foregroundColor, int backgroundColor, Bitmap logo) {
try {
BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, size, size, HINTS);
int[] pixels = new int[size * size];
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
if (matrix.get(x, y)) {
pixels[y * size + x] = foregroundColor;
} else {
pixels[y * size + x] = backgroundColor;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, size, 0, 0, size, size);
return addLogoToQRCode(bitmap, logo);
} catch (Exception e) {
return null;
}
}
示例4: BitMatrixToBitmap
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
/**
* BitMatrix轉換成Bitmap
*
* @param matrix
* @return
*/
private static Bitmap BitMatrixToBitmap(BitMatrix matrix) {
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
int offset = y * width;
for (int x = 0; x < width; x++) {
if(matrix.get(x,y)){
pixels[offset + x] =BLACK; //上麵圖案的顏色
}else{
pixels[offset + x] =WHITE;//底色
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
Log.e("hongliang","width:"+bitmap.getWidth()+" height:"+bitmap.getHeight());
return bitmap;
}
示例5: Create2DCode
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
/**
* 用字符串生成二維碼
*
* @param str
* @author J!nl!n
* @return
* @throws WriterException
*/
public Bitmap Create2DCode(String str) 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, 480, 480, hints);
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] = 0xff000000;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
// 通過像素數組生成bitmap,具體參考api
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
示例6: createQRCode
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
public static Bitmap createQRCode(String str, int size) 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, size, size);
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for(int x = 0; x < width; x ++){
for(int y = 0; y < height; y ++){
if(matrix.get(x, y)){
pixels[y * width + x] = BLACK;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
示例7: moduleSize
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
private static float moduleSize(int[] leftTopBlack, BitMatrix image) throws NotFoundException {
int height = image.getHeight();
int width = image.getWidth();
int x = leftTopBlack[0];
int y = leftTopBlack[1];
boolean inBlack = true;
int transitions = 0;
while (x < width && y < height) {
if (inBlack != image.get(x, y)) {
if (++transitions == 5) {
break;
}
inBlack = !inBlack;
}
x++;
y++;
}
if (x == width || y == height) {
throw NotFoundException.getNotFoundInstance();
}
return (x - leftTopBlack[0]) / 7.0f;
}
示例8: createQRCodeWithLogo3
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
/**
* bitmap作為底色
*
* @param text
* @param size
* @param mBitmap
* @return
*/
public static Bitmap createQRCodeWithLogo3(String text, int size, Bitmap mBitmap) {
try {
IMAGE_HALFWIDTH = size / 10;
Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
BitMatrix bitMatrix = new QRCodeWriter().encode(text,
BarcodeFormat.QR_CODE, size, size, hints);
//將logo圖片按martix設置的信息縮放
mBitmap = Bitmap.createScaledBitmap(mBitmap, size, size, false);
int[] pixels = new int[size * size];
int color = 0xfff92736;
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * size + x] = color;
} else {
pixels[y * size + x] = mBitmap.getPixel(x, y) & 0x66ffffff;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(size, size,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, size, 0, 0, size, size);
return bitmap;
} catch (WriterException e) {
e.printStackTrace();
return null;
}
}
示例9: deleteWhite
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
public static BitMatrix deleteWhite(BitMatrix matrix){
int[] rec = matrix.getEnclosingRectangle();
int resWidth = rec[2] + 1;
int resHeight = rec[3] + 1;
BitMatrix resMatrix = new BitMatrix(resWidth, resHeight);
resMatrix.clear();
for (int i = 0; i < resWidth; i++) {
for (int j = 0; j < resHeight; j++) {
if (matrix.get(i + rec[0], j + rec[1]))
resMatrix.set(i, j);
}
}
return resMatrix;
}
示例10: 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;
}
示例11: encodeAsBitmap
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
Bitmap encodeAsBitmap() throws WriterException {
String contentsToEncode = contents;
if (contentsToEncode == null) {
return null;
}
Map<EncodeHintType,Object> hints = null;
String encoding = guessAppropriateEncoding(contentsToEncode);
if (encoding != null) {
hints = new EnumMap<EncodeHintType,Object>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, encoding);
}
BitMatrix result;
try {
result = new MultiFormatWriter().encode(contentsToEncode, format, dimension, dimension, hints);
} catch (IllegalArgumentException iae) {
// Unsupported format
return null;
}
int width = result.getWidth();
int height = result.getHeight();
int[] pixels = new int[width * height];
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;
}
示例12: renderQRCode
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
private Bitmap renderQRCode(String barcode, BarcodeFormat format, int width) throws WriterException {
float scale = this.context.getResources().getDisplayMetrics().density;
width *= scale * 0.6;
Writer barWriter = new MultiFormatWriter();
Bitmap bitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);
BitMatrix bm = barWriter.encode(barcode, format, width, width);
for (int j = 0; j < width; j++) {
int[] row = new int[width];
for (int i = 0; i < width; i++) {
row[i] = bm.get(i, j) ? Color.BLACK : Color.TRANSPARENT;
}
bitmap.setPixels(row, 0, width, 0, j, width, 1);
}
CropUtility cropUtility = new CropUtility();
Bitmap cropped = cropUtility.rectangularCrop(bitmap, Color.TRANSPARENT, 0);
FactoryManager manager = new FactoryManager();
ShapeFactory shapeFactory = manager.getRecommendedShapeFactory();
return shapeFactory.createShape(new RectangleShape(this.context), cropped, Constants.LOGO_BACKGROUND_COLOUR, padding);
}
示例13: createQRImage
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
private static void createQRImage(File qrFile, String qrCodeText, int size,
String fileType) throws WriterException, IOException {
// Create the ByteMatrix for the QR-Code that encodes the given String
Hashtable hintMap = new Hashtable();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix byteMatrix = qrCodeWriter.encode(qrCodeText,
BarcodeFormat.QR_CODE, size, size, hintMap);
// Make the BufferedImage that are to hold the QRCode
int matrixWidth = byteMatrix.getWidth();
BufferedImage image = new BufferedImage(matrixWidth, matrixWidth,
BufferedImage.TYPE_INT_RGB);
image.createGraphics();
Graphics2D graphics = (Graphics2D) image.getGraphics();
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, matrixWidth, matrixWidth);
// Paint and save the image using the ByteMatrix
graphics.setColor(Color.BLACK);
for (int i = 0; i < matrixWidth; i++) {
for (int j = 0; j < matrixWidth; j++) {
if (byteMatrix.get(i, j)) {
graphics.fillRect(i, j, 1, 1);
}
}
}
ImageIO.write(image, fileType, qrFile);
}
示例14: createQRCode
import com.google.zxing.common.BitMatrix; //導入方法依賴的package包/類
/**
* 創建二維碼
*
* @param content content
* @param widthPix widthPix
* @param heightPix heightPix
* @param logoBm logoBm
* @return 二維碼
*/
public static Bitmap createQRCode(String content, int widthPix, int heightPix, Bitmap logoBm) {
try {
if (content == null || "".equals(content)) {
return null;
}
// 配置參數
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
// 容錯級別
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
// 圖像數據轉換,使用了矩陣轉換
BitMatrix bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, widthPix, heightPix, hints);
int[] pixels = new int[widthPix * heightPix];
// 下麵這裏按照二維碼的算法,逐個生成二維碼的圖片,
// 兩個for循環是圖片橫列掃描的結果
for (int y = 0; y < heightPix; y++) {
for (int x = 0; x < widthPix; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * widthPix + x] = 0xff000000;
} else {
pixels[y * widthPix + x] = 0xffffffff;
}
}
}
// 生成二維碼圖片的格式,使用ARGB_8888
Bitmap bitmap = Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix);
if (logoBm != null) {
bitmap = addLogo(bitmap, logoBm);
}
//必須使用compress方法將bitmap保存到文件中再進行讀取。直接返回的bitmap是沒有任何壓縮的,內存消耗巨大!
return bitmap;
} catch (WriterException e) {
e.printStackTrace();
}
return null;
}
示例15: 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;
}