Note that there are some explanatory texts on larger screens.

plurals
  1. PONullpointerException onPictureTaken
    primarykey
    data
    text
    <p>I got some problems with taking pictures via android camera.</p> <p>The main purpose is by using <code>CameraControlView</code> preview the camera and take picture via a button.</p> <pre><code>String fileName = Environment.getExternalStorageDirectory().getPath() + "/sample_picture.jpg"; Bitmap photo; mOpenCvCameraView.takePicture(fileName); //viewNavi.setDisplayedChild(viewNavi.indexOfChild(findViewById(R.id.image_view))); viewNavi.showNext(); Bitmap newp =BitmapFactory.decodeFile(fileName); if(newp==null) return; ImageView imgViewResult = (ImageView) findViewById(R.id.imgViewResult); imgViewResult.setImageBitmap(newp); </code></pre> <p><code>CameraControlView.takePicture(fileLocation);</code> I want to use the saved picture on an imageView after that point but I could not, because saving the picture progress is not done yet (which is run by <code>OnPictureTaken</code>). So I wanted to be sure if the taking picture process is done. Then I found a useful explaination on the internet which is the <code>OnPictureTaken</code> progress is the responsible method for saving pictures:</p> <pre><code>public void onPictureTaken(byte[] data, Camera camera) { Log.i(TAG, "Saving a bitmap to file"); // The camera preview was automatically stopped. Start it again. mCamera.startPreview(); mCamera.setPreviewCallback(this); // Write the image in a file (in jpeg format) /*My code ImageView imgResult = (ImageView) findViewById(R.id.imgViewResult); Bitmap newp = BitmapFactory.decodeByteArray(data, 0, data.length); imgResult.setImageBitmap(newp); */ try { FileOutputStream fos = new FileOutputStream(mPictureFileName); fos.write(data); fos.close(); } catch (java.io.IOException e) { Log.e("PictureDemo", "Exception in photoCallback", e); } isPictureTaken = true; } </code></pre> <p>The real problem is when I tried to add this code segment:</p> <pre><code> ImageView imgResult = (ImageView) findViewById(R.id.imgViewResult); Bitmap newp = BitmapFactory.decodeByteArray(data, 0, data.length); imgResult.setImageBitmap(newp); </code></pre> <p>In to the <code>onPictureTaken</code> as shown above. I got a <code>NullPointerException</code>.</p> <p>Is there a way that only take taken picture into a bitmap, and in sync way (means the way I have been using is not suitable for my project. When I want to setImageBitmap after takePicture. The code sends me previous taken pic[because I am using the same save location and overwrite the pic] or null) </p> <p>Any explanation would be great.</p> <p>Thanks for your time.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload