Loading

Tuesday, January 4, 2011

Save the camera image using MediaStore

Further work on the last exercise "Implement takePicture function of Android Camera". Modify onPictureTaken() method to save the captured image in Android standard location for images, using Android's MediaStore.



Save the camera image using MediaStore



 PictureCallback myPictureCallback_JPG = new PictureCallback(){



@Override

public void onPictureTaken(byte[] arg0, Camera arg1) {

// TODO Auto-generated method stub

/*Bitmap bitmapPicture

= BitmapFactory.decodeByteArray(arg0, 0, arg0.length); */



Uri uriTarget = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, new ContentValues());



OutputStream imageFileOS;

try {

imageFileOS = getContentResolver().openOutputStream(uriTarget);

imageFileOS.write(arg0);

imageFileOS.flush();

imageFileOS.close();



Toast.makeText(AndroidCamera.this,

"Image saved: " + uriTarget.toString(),

Toast.LENGTH_LONG).show();



} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}



camera.startPreview();

}};






Download the files.


- Download the project




next:

- Start Camera auto-focusing, autoFocus()





SHARE TWEET

Thank you for reading this article Save the camera image using MediaStore With URL http://x-tutorials.blogspot.com/2011/01/save-camera-image-using-mediastore.html. Also a time to read the other articles.

0 comments:

Write your comment for this article Save the camera image using MediaStore above!