use of com.google.zxing.BinaryBitmap in project protools by SeanDragon.
the class MatrixToImageWriterEx method decode.
/**
* 解码
*
* @param filePath
*
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static String decode(String filePath) throws IOException, NotFoundException {
BufferedImage image;
image = ImageIO.read(new File(filePath));
if (image == null) {
return "Could not decode image";
}
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result;
Hashtable hints = new Hashtable();
hints.put(EncodeHintType.CHARACTER_SET, StrConst.DEFAULT_CHARSET_NAME);
result = new MultiFormatReader().decode(bitmap, hints);
return result.getText();
}
use of com.google.zxing.BinaryBitmap in project SmartMesh_Android by SmartMeshFoundation.
the class ScanLargePic method scanningImage.
public Result scanningImage(String path) {
if (TextUtils.isEmpty(path)) {
return null;
}
File file = new File(path);
if (!file.exists()) {
return null;
}
Hashtable<DecodeHintType, Object> hints = new Hashtable<>();
hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap scanBitmap = BitmapFactory.decodeFile(path, options);
options.inJustDecodeBounds = false;
int sampleSize = (int) (options.outHeight / (float) 512);
if (sampleSize <= 0)
sampleSize = 1;
options.inSampleSize = sampleSize;
scanBitmap = BitmapFactory.decodeFile(path, options);
int width = scanBitmap.getWidth();
int height = scanBitmap.getHeight();
int[] pixels = new int[width * height];
scanBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
try {
return reader.decode(bitmap1, hints);
} catch (NotFoundException e) {
e.printStackTrace();
} catch (ChecksumException e) {
e.printStackTrace();
} catch (FormatException e) {
e.printStackTrace();
}
return null;
}
use of com.google.zxing.BinaryBitmap in project BlogSource by TeachCourse.
the class DecodeHandler method decode.
/**
* Decode the data within the viewfinder rectangle, and time how long it
* took. For efficiency, reuse the same reader objects from one decode to
* the next.
*
* @param data
* The YUV preview frame.
* @param width
* The width of the preview frame.
* @param height
* The height of the preview frame.
*/
private void decode(byte[] data, int width, int height) {
long start = System.currentTimeMillis();
Result rawResult = null;
/**
* 竖屏显示开始 *
*/
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) rotatedData[x * height + height - y - 1] = data[x + y * width];
}
// Here we are swapping, that's the difference to #11
int tmp = width;
width = height;
height = tmp;
data = rotatedData;
/**
* 竖屏显示结束 *
*/
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
if (rawResult != null) {
long end = System.currentTimeMillis();
Log.d(TAG, "Found barcode (" + (end - start) + " ms):\n" + rawResult.toString());
Message message = Message.obtain(activity.getHandler(), MessageIDs.decode_succeeded, rawResult);
Bundle bundle = new Bundle();
bundle.putParcelable(DecodeThread.BARCODE_BITMAP, source.renderCroppedGreyscaleBitmap());
message.setData(bundle);
// LogUtil.d(TAG, "Sending decode succeeded message...");
message.sendToTarget();
} else {
Message message = Message.obtain(activity.getHandler(), MessageIDs.decode_failed);
message.sendToTarget();
}
}
use of com.google.zxing.BinaryBitmap in project tephra by heisedebaise.
the class QrCodeImpl method read.
@Override
public String read(InputStream inputStream) {
try {
String string = reader.decode(new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(inputStream))))).getText();
inputStream.close();
return string;
} catch (Throwable e) {
logger.warn(e, "读取二维码图片内容时发生异常!");
return null;
}
}
use of com.google.zxing.BinaryBitmap in project MyBaseApplication by BanShouWeng.
the class DecodeHandler method decode.
/**
* Decode the data within the viewfinder rectangle, and time how long it
* took. For efficiency, reuse the same reader objects from one decode to
* the next.
*
* @param data
* The YUV preview frame.
* @param width
* The width of the preview frame.
* @param height
* The height of the preview frame.
*/
private void decode(byte[] data, int width, int height) {
long start = System.currentTimeMillis();
Result rawResult = null;
/**
* 竖屏显示开始
*/
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) rotatedData[x * height + height - y - 1] = data[x + y * width];
}
// Here we are swapping, that's the difference to #11
int tmp = width;
width = height;
height = tmp;
data = rotatedData;
/**
* 竖屏显示结束 *
*/
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
if (rawResult != null) {
long end = System.currentTimeMillis();
Log.d(TAG, "Found barcode (" + (end - start) + " ms):\n" + rawResult.toString());
Message message = Message.obtain(activity.getHandler(), MessageIDs.decode_succeeded, rawResult);
Bundle bundle = new Bundle();
bundle.putParcelable(DecodeThread.BARCODE_BITMAP, source.renderCroppedGreyscaleBitmap());
message.setData(bundle);
// Log.d(TAG, "Sending decode succeeded message...");
message.sendToTarget();
} else {
Message message = Message.obtain(activity.getHandler(), MessageIDs.decode_failed);
message.sendToTarget();
}
}
Aggregations