mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Maybe avoid a weird NPE
git-svn-id: https://zxing.googlecode.com/svn/trunk@2135 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
ae54c38817
commit
8d42aef4ce
|
@ -122,6 +122,9 @@ public final class EncodeActivity extends Activity {
|
||||||
Log.w(TAG, we);
|
Log.w(TAG, we);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (bitmap == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
File bsRoot = new File(Environment.getExternalStorageDirectory(), "BarcodeScanner");
|
File bsRoot = new File(Environment.getExternalStorageDirectory(), "BarcodeScanner");
|
||||||
File barcodesRoot = new File(bsRoot, "Barcodes");
|
File barcodesRoot = new File(bsRoot, "Barcodes");
|
||||||
|
@ -182,10 +185,18 @@ public final class EncodeActivity extends Activity {
|
||||||
if (intent == null) {
|
if (intent == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
boolean useVCard = intent.getBooleanExtra(USE_VCARD_KEY, false);
|
boolean useVCard = intent.getBooleanExtra(USE_VCARD_KEY, false);
|
||||||
qrCodeEncoder = new QRCodeEncoder(this, intent, smallerDimension, useVCard);
|
qrCodeEncoder = new QRCodeEncoder(this, intent, smallerDimension, useVCard);
|
||||||
Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
|
Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
|
||||||
|
if (bitmap == null) {
|
||||||
|
Log.w(TAG, "Could not encode barcode");
|
||||||
|
showErrorMessage(R.string.msg_encode_contents_failed);
|
||||||
|
qrCodeEncoder = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ImageView view = (ImageView) findViewById(R.id.image_view);
|
ImageView view = (ImageView) findViewById(R.id.image_view);
|
||||||
view.setImageBitmap(bitmap);
|
view.setImageBitmap(bitmap);
|
||||||
|
|
||||||
|
|
|
@ -302,14 +302,18 @@ final class QRCodeEncoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap encodeAsBitmap() throws WriterException {
|
Bitmap encodeAsBitmap() throws WriterException {
|
||||||
|
String contentsToEncode = contents;
|
||||||
|
if (contentsToEncode == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Map<EncodeHintType,Object> hints = null;
|
Map<EncodeHintType,Object> hints = null;
|
||||||
String encoding = guessAppropriateEncoding(contents);
|
String encoding = guessAppropriateEncoding(contentsToEncode);
|
||||||
if (encoding != null) {
|
if (encoding != null) {
|
||||||
hints = new EnumMap<EncodeHintType,Object>(EncodeHintType.class);
|
hints = new EnumMap<EncodeHintType,Object>(EncodeHintType.class);
|
||||||
hints.put(EncodeHintType.CHARACTER_SET, encoding);
|
hints.put(EncodeHintType.CHARACTER_SET, encoding);
|
||||||
}
|
}
|
||||||
MultiFormatWriter writer = new MultiFormatWriter();
|
MultiFormatWriter writer = new MultiFormatWriter();
|
||||||
BitMatrix result = writer.encode(contents, format, dimension, dimension, hints);
|
BitMatrix result = writer.encode(contentsToEncode, format, dimension, dimension, hints);
|
||||||
int width = result.getWidth();
|
int width = result.getWidth();
|
||||||
int height = result.getHeight();
|
int height = result.getHeight();
|
||||||
int[] pixels = new int[width * height];
|
int[] pixels = new int[width * height];
|
||||||
|
|
Loading…
Reference in a new issue