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:
srowen 2012-01-29 21:02:59 +00:00
parent ae54c38817
commit 8d42aef4ce
2 changed files with 17 additions and 2 deletions

View file

@ -122,6 +122,9 @@ public final class EncodeActivity extends Activity {
Log.w(TAG, we);
return;
}
if (bitmap == null) {
return;
}
File bsRoot = new File(Environment.getExternalStorageDirectory(), "BarcodeScanner");
File barcodesRoot = new File(bsRoot, "Barcodes");
@ -182,10 +185,18 @@ public final class EncodeActivity extends Activity {
if (intent == null) {
return;
}
try {
boolean useVCard = intent.getBooleanExtra(USE_VCARD_KEY, false);
qrCodeEncoder = new QRCodeEncoder(this, intent, smallerDimension, useVCard);
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);
view.setImageBitmap(bitmap);

View file

@ -302,14 +302,18 @@ final class QRCodeEncoder {
}
Bitmap encodeAsBitmap() throws WriterException {
String contentsToEncode = contents;
if (contentsToEncode == null) {
return null;
}
Map<EncodeHintType,Object> hints = null;
String encoding = guessAppropriateEncoding(contents);
String encoding = guessAppropriateEncoding(contentsToEncode);
if (encoding != null) {
hints = new EnumMap<EncodeHintType,Object>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, encoding);
}
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 height = result.getHeight();
int[] pixels = new int[width * height];