Created
September 19, 2019 03:01
-
-
Save jesselima/e3334703df6782da1024b2fb056fdbf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected Result doInBackground(Void... params) | |
{ | |
try { | |
InputStream inputStream = activity.getContentResolver().openInputStream(uri); | |
Bitmap bitmap = BitmapFactory.decodeStream(inputStream); | |
if (bitmap == null) { | |
Log.e(TAG, "uri is not a bitmap," + uri.toString()); | |
return null; | |
} | |
int width = bitmap.getWidth(), height = bitmap.getHeight(); | |
int[] pixels = new int[width * height]; | |
bitmap.getPixels(pixels, 0, width, 0, 0, width, height); | |
bitmap.recycle(); | |
bitmap = null; | |
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels); | |
BinaryBitmap bBitmap = new BinaryBitmap(new HybridBinarizer(source)); | |
MultiFormatReader reader = new MultiFormatReader(); | |
try { | |
Result result = reader.decode(bBitmap); | |
return result; | |
} catch (NotFoundException e) { | |
Log.e(TAG, "decode exception", e); | |
return null; | |
} | |
} catch (FileNotFoundException e) { | |
Log.e(TAG, "can not open file" + uri.toString(), e); | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment