本文整理汇总了Java中com.google.zxing.RGBLuminanceSource类的典型用法代码示例。如果您正苦于以下问题:Java RGBLuminanceSource类的具体用法?Java RGBLuminanceSource怎么用?Java RGBLuminanceSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RGBLuminanceSource类属于com.google.zxing包,在下文中一共展示了RGBLuminanceSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
public static String convert(Bitmap bitmap) {
try {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
RGBLuminanceSource rgbLuminanceSource = new RGBLuminanceSource(
width, height, pixels);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
rgbLuminanceSource));
HashMap<DecodeHintType, Object> hints = new HashMap<DecodeHintType, Object>();
hints.put(DecodeHintType.CHARACTER_SET, DEFAULT_CHARSET);
MultiFormatReader multiFormatReader = new MultiFormatReader();
Result result = multiFormatReader.decode(binaryBitmap, hints);
return result.getText();
} catch (Exception e) {
return null;
}
}
示例2: syncDecodeQRCode
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
/**
* 同步解析bitmap二维码。该方法是耗时操作,请在子线程中调用。
*
* @param bitmap 要解析的二维码图片
* @return 返回二维码图片里的内容 或 null
*/
public static String syncDecodeQRCode(Bitmap bitmap) {
try {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
Result result = new MultiFormatReader().decode(new BinaryBitmap(new HybridBinarizer(source)), HINTS);
return result.getText();
} catch (Exception e) {
return null;
}
}
示例3: decodeWithZxing
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
public String decodeWithZxing(Bitmap bitmap) {
MultiFormatReader multiFormatReader = new MultiFormatReader();
multiFormatReader.setHints(changeZXingDecodeDataMode());
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
Result rawResult = null;
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
if (source != null) {
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(binaryBitmap);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
}
return rawResult != null ? rawResult.getText() : null;
}
示例4: decodeWithZxing
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
public Result decodeWithZxing(Bitmap bitmap) {
MultiFormatReader multiFormatReader = new MultiFormatReader();
multiFormatReader.setHints(changeZXingDecodeDataMode());
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
Result rawResult = null;
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(binaryBitmap);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
return rawResult;
}
示例5: scanBitmap
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
public Result scanBitmap(Bitmap bitmap) throws FormatException, ChecksumException, NotFoundException {
Reader reader = new MultiFormatReader();
Result result;
int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
//copy pixel data from the Bitmap into the 'intArray' array
bitmap.getPixels(intArray, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
LuminanceSource source = new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray);
BinaryBitmap bMap = new BinaryBitmap(new HybridBinarizer(source));
result = reader.decode(bMap);
return result;
}
示例6: decode_qr
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
/**
* Writes decoded message to Decoded.txt
* @param f Input QRCode image
*/
public void decode_qr(String f)
{
try
{
tv= (TextView)findViewById(R.id.dqr);
tv.setText("");
Bitmap bmp=BitmapFactory.decodeFile(f); //import QRCode image file
int width = bmp.getWidth(), height = bmp.getHeight();
int[] pixels = new int[width * height];
bmp.getPixels(pixels, 0, width, 0, 0, width, height);
bmp.recycle();
bmp = null;
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result qr_result = new QRCodeReader().decode(bitmap);
tv.setText("Successfully Decoded!\n");
tv.append("Decoded file is at:\n");
write_to_file(qr_result.getText().toString());
}
catch(Exception e)
{
Log.create_log(e, getApplicationContext());
}
}
示例7: decode
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
public String decode(final Bitmap image){
final long start = System.currentTimeMillis();
final int width = image.getWidth(), height = image.getHeight();
final int[] pixels = new int[width * height];
image.getPixels(pixels, 0, width, 0, 0, width, height);
final RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
Result rawResult = mMultiFormatReader.decodeWithState(bitmap);
final long end = System.currentTimeMillis();
Log.d(TAG, "QRCode decode in " + (end - start) + "ms");
Log.d(TAG, rawResult.toString());
return rawResult.getText();
} catch (NotFoundException re) {
Log.w(TAG, re);
return null;
}finally {
mMultiFormatReader.reset();
}
}
示例8: scanningImage
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
protected Result scanningImage(String path) {
if (StringUtil.isBlank(path)) {
return null;
}
// DecodeHintType 和EncodeHintType
Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); // 设置二维码内容的编码
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; // 先获取原大小
scanBitmap = BitmapFactory.decodeFile(path, options);
options.inJustDecodeBounds = false; // 获取新的大小
int sampleSize = (int) (options.outHeight / (float) 200);
if (sampleSize <= 0)
sampleSize = 1;
options.inSampleSize = sampleSize;
scanBitmap = BitmapFactory.decodeFile(path, options);
int width = scanBitmap.getWidth(), height = scanBitmap.getHeight();
int[] pixels = new int[width * height];
scanBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
scanBitmap.recycle();
scanBitmap = null;
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 (Exception e) {
e.printStackTrace();
}
return null;
}
示例9: zxing
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
public Result[] zxing( Mat inputImage ) throws ChecksumException, FormatException {
int w = inputImage.width();
int h = inputImage.height();
Mat southEast;
if (mBugRotate) {
southEast = inputImage.submat(h-h/4 , h , 0 , w/2 - h/4 );
} else {
southEast = inputImage.submat(0, h / 4, w / 2 + h / 4, w);
}
Bitmap bMap = Bitmap.createBitmap(southEast.width(), southEast.height(), Bitmap.Config.ARGB_8888);
org.opencv.android.Utils.matToBitmap(southEast, bMap);
southEast.release();
int[] intArray = new int[bMap.getWidth()*bMap.getHeight()];
//copy pixel data from the Bitmap into the 'intArray' array
bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());
LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(),intArray);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result[] results = {};
try {
results = qrCodeMultiReader.decodeMultiple(bitmap);
}
catch (NotFoundException ignored) {
}
return results;
}
示例10: createLuminanceSource
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
private static RGBLuminanceSource createLuminanceSource(InputStream inputStream) {
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
bitmap.recycle();
return new RGBLuminanceSource(width, height, pixels);
}
示例11: processImage
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
@Override
public Bitmap processImage(Bitmap bMap) {
int[] intArray = new int[bMap.getWidth()*bMap.getHeight()];
//copy pixel data from the Bitmap into the 'intArray' array
bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());
LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(),intArray);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result;
try {
result = new MultiFormatReader().decode(bitmap);
lastResult = result.getText();
lastFoundTime = System.currentTimeMillis();
fire(result.getText());
} catch (NotFoundException e) {
//that's ok
if (!lastResult.equals("")) //if result was not empty, clear old result
{
long mt1 = System.currentTimeMillis();
if (mt1 - lastFoundTime > CLEAR_RESULT_TIMEOUT) {
lastFoundTime = mt1;
fire("");
lastResult = "";
}
}
}
return bMap;
}
示例12: decodePureBitmap
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
public static Result decodePureBitmap(Bitmap bmp) throws FormatException, ChecksumException, NotFoundException {
int width = bmp.getWidth(), height = bmp.getHeight();
int[] pixels = new int[width * height];
bmp.getPixels(pixels, 0, width, 0, 0, width, height);
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
QRCodeReader reader = new QRCodeReader();
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
return reader.decode(binaryBitmap, hints);
}
示例13: handleMessage
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
@Override
public void handleMessage(Message message) {
if (running) {
switch (message.what) {
case R.id.decode:
RenderableLuminanceSource source = null;
byte[] data = (byte[]) message.obj;
if (data != null) {
source = activity.getCameraManager().buildLuminanceSource(data);
}
decode(source);
break;
case R.id.decode_image:
Bitmap bitmap = (Bitmap) message.obj;
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
decodeLocalImage(new RGBLuminanceSource(width, height, pixels));
break;
case R.id.quit:
running = false;
enhancedDecodeExecutor.shutdown();
Looper.myLooper().quit();
break;
}
}
}
示例14: binarization
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
private Bitmap binarization(Bitmap bitmap, int lowColor, int highColor) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int pixels[] = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
LuminanceSource source = new RGBLuminanceSource(width, height, pixels);
Binarizer binarizer = new HybridBinarizer(source);
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
try {
BitMatrix matrix = binarizer.getBlackMatrix();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (matrix.get(j, i)) {
result.setPixel(j, i, highColor);
} else {
result.setPixel(j, i, lowColor);
}
}
}
} catch (NotFoundException e) {
e.printStackTrace();
}
return result;
}
示例15: binarization
import com.google.zxing.RGBLuminanceSource; //导入依赖的package包/类
/**
* 二值化
*
* @param bitmap
* @return
*/
private Bitmap binarization(Bitmap bitmap, int lowColor, int highStartColor, int highEndColor) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int pixels[] = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
LuminanceSource source = new RGBLuminanceSource(width, height, pixels);
Binarizer binarizer = new HybridBinarizer(source);
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
try {
BitMatrix matrix = binarizer.getBlackMatrix();
int highColor;
for (int i = 0; i < height; i++) {
// highColor = getGradientColor(highStartColor, highEndColor, i / (float) height);
highColor = getGradientColorByCurve(highStartColor, highEndColor, 0, height, i);
for (int j = 0; j < width; j++) {
if (matrix.get(j, i)) {
result.setPixel(j, i, highColor);
} else {
result.setPixel(j, i, lowColor);
}
}
}
} catch (NotFoundException e) {
e.printStackTrace();
}
return result;
}