use of com.google.zxing.DecodeHintType in project camel by apache.
the class BarcodeDataFormatTest method testAddToHintMapDecodeHintTypeObject.
/**
* Test of addToHintMap method, of class BarcodeDataFormat.
*/
@Test
public final void testAddToHintMapDecodeHintTypeObject() {
DecodeHintType hintType = DecodeHintType.CHARACTER_SET;
Object value = "UTF-8";
BarcodeDataFormat instance = new BarcodeDataFormat();
instance.addToHintMap(hintType, value);
assertTrue(instance.getReaderHintMap().containsKey(hintType));
assertEquals(instance.getReaderHintMap().get(hintType), value);
}
use of com.google.zxing.DecodeHintType in project camel by apache.
the class BarcodeDataFormatTest method testRemoveFromHintMapDecodeHintType.
/**
* Test of removeFromHintMap method, of class BarcodeDataFormat.
*/
@Test
public final void testRemoveFromHintMapDecodeHintType() {
DecodeHintType hintType = DecodeHintType.TRY_HARDER;
BarcodeDataFormat instance = new BarcodeDataFormat();
instance.removeFromHintMap(hintType);
assertFalse(instance.getReaderHintMap().containsKey(hintType));
}
use of com.google.zxing.DecodeHintType in project barcodescanner by dm77.
the class ZXingScannerView method initMultiFormatReader.
private void initMultiFormatReader() {
Map<DecodeHintType, Object> hints = new EnumMap<DecodeHintType, Object>(DecodeHintType.class);
hints.put(DecodeHintType.POSSIBLE_FORMATS, getFormats());
mMultiFormatReader = new MultiFormatReader();
mMultiFormatReader.setHints(hints);
}
use of com.google.zxing.DecodeHintType in project zxing-android-embedded by journeyapps.
the class DecodeHintManager method parseDecodeHints.
static Map<DecodeHintType, ?> parseDecodeHints(Uri inputUri) {
String query = inputUri.getEncodedQuery();
if (query == null || query.isEmpty()) {
return null;
}
// Extract parameters
Map<String, String> parameters = splitQuery(query);
Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
for (DecodeHintType hintType : DecodeHintType.values()) {
if (hintType == DecodeHintType.CHARACTER_SET || hintType == DecodeHintType.NEED_RESULT_POINT_CALLBACK || hintType == DecodeHintType.POSSIBLE_FORMATS) {
// This hint is specified in another way
continue;
}
String parameterName = hintType.name();
String parameterText = parameters.get(parameterName);
if (parameterText == null) {
continue;
}
if (hintType.getValueType().equals(Object.class)) {
// This is an unspecified type of hint content. Use the value as is.
// TODO: Can we make a different assumption on this?
hints.put(hintType, parameterText);
continue;
}
if (hintType.getValueType().equals(Void.class)) {
// Void hints are just flags: use the constant specified by DecodeHintType
hints.put(hintType, Boolean.TRUE);
continue;
}
if (hintType.getValueType().equals(String.class)) {
// A string hint: use the decoded value.
hints.put(hintType, parameterText);
continue;
}
if (hintType.getValueType().equals(Boolean.class)) {
// An empty parameter is simply a flag-style parameter, assuming true
if (parameterText.isEmpty()) {
hints.put(hintType, Boolean.TRUE);
} else if ("0".equals(parameterText) || "false".equalsIgnoreCase(parameterText) || "no".equalsIgnoreCase(parameterText)) {
hints.put(hintType, Boolean.FALSE);
} else {
hints.put(hintType, Boolean.TRUE);
}
continue;
}
if (hintType.getValueType().equals(int[].class)) {
// Strip a trailing comma as in Java style array initialisers.
if (!parameterText.isEmpty() && parameterText.charAt(parameterText.length() - 1) == ',') {
parameterText = parameterText.substring(0, parameterText.length() - 1);
}
String[] values = COMMA.split(parameterText);
int[] array = new int[values.length];
for (int i = 0; i < values.length; i++) {
try {
array[i] = Integer.parseInt(values[i]);
} catch (NumberFormatException ignored) {
Log.w(TAG, "Skipping array of integers hint " + hintType + " due to invalid numeric value: '" + values[i] + '\'');
array = null;
break;
}
}
if (array != null) {
hints.put(hintType, array);
}
continue;
}
Log.w(TAG, "Unsupported hint type '" + hintType + "' of type " + hintType.getValueType());
}
Log.i(TAG, "Hints from the URI: " + hints);
return hints;
}
use of com.google.zxing.DecodeHintType in project android-zxingLibrary by yipianfengye.
the class CodeUtils method analyzeBitmap.
/**
* 解析二维码图片工具类
* @param analyzeCallback
*/
public static void analyzeBitmap(String path, AnalyzeCallback analyzeCallback) {
/**
* 首先判断图片的大小,若图片过大,则执行图片的裁剪操作,防止OOM
*/
BitmapFactory.Options options = new BitmapFactory.Options();
// 先获取原大小
options.inJustDecodeBounds = true;
Bitmap mBitmap = BitmapFactory.decodeFile(path, options);
// 获取新的大小
options.inJustDecodeBounds = false;
int sampleSize = (int) (options.outHeight / (float) 400);
if (sampleSize <= 0)
sampleSize = 1;
options.inSampleSize = sampleSize;
mBitmap = BitmapFactory.decodeFile(path, options);
MultiFormatReader multiFormatReader = new MultiFormatReader();
// 解码的参数
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(2);
// 可以解析的编码类型
Vector<BarcodeFormat> decodeFormats = new Vector<BarcodeFormat>();
if (decodeFormats == null || decodeFormats.isEmpty()) {
decodeFormats = new Vector<BarcodeFormat>();
// 这里设置可扫描的类型,我这里选择了都支持
decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
}
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
// 设置继续的字符编码格式为UTF8
// hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
// 设置解析配置参数
multiFormatReader.setHints(hints);
// 开始对图像资源解码
Result rawResult = null;
try {
rawResult = multiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(new BitmapLuminanceSource(mBitmap))));
} catch (Exception e) {
e.printStackTrace();
}
if (rawResult != null) {
if (analyzeCallback != null) {
analyzeCallback.onAnalyzeSuccess(mBitmap, rawResult.getText());
}
} else {
if (analyzeCallback != null) {
analyzeCallback.onAnalyzeFailed();
}
}
}
Aggregations