mirror of
https://github.com/zxing/zxing.git
synced 2025-01-13 04:07:27 -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);
|
||||
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);
|
||||
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in a new issue