Good Day I'm trying to display captured image in gridview as well save it in Sqlite Database..in the logcat appear this
E/BitmapFactory: Unable to decode stream: java.lang.NullPointerException W/System.err: java.lang.NullPointerException W/System.err: at .CameraFragment.previewCapturedImage(CameraFragment.java:259 W/System.err: at CameraFragment.onActivityResult(CameraFragment.java:215)
which point to this line in my code
bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
here is the code
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==CAMERA_CAPTURE_IMAGE_REQUEST_CODE&&resultCode == Activity.RESULT_OK){
previewCapturedImage();
Toast.makeText(getActivity(), "InvoiceFile saved successfully", Toast.LENGTH_LONG).show();
}
else if (resultCode == getActivity().RESULT_CANCELED) {
// user cancelled Image capture
Toast.makeText(getActivity(), "User cancelled image capture", Toast.LENGTH_SHORT)
.show();}
else {
// failed to capture image
Toast.makeText(getActivity(), "Sorry! Failed to capture image", Toast.LENGTH_SHORT)
.show();
}}
private void previewCapturedImage() {
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
byte[] byte_arr = stream.toByteArray();
images.setImageBlob(byte_arr);
// Add Image Path To List
myLists.add(images);
// Refresh Gridview Image Thumbnails
adapter.notifyDataSetChanged();
DBadapter.insertImage(images);
}
any Help will be appreciate
Aucun commentaire:
Enregistrer un commentaire