Use this code to save the image on the SD card, and also create a directory to store the captured image
File photo = new File(Environment.getExternalStorageDirectory()+"/photofolder");
System.out.println(photo.toString());
boolean success = false;
if(!photo.exists())
{
success = photo.mkdirs();
}
if(!success)
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photo = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Android/data/"+getApplicationContext().getPackageName()+"/files/Receipt", imagename+".png");
Toast.makeText(this, photo.toString(), Toast.LENGTH_LONG);
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photo));
Uri imageurl = Uri.fromFile(photo);
startActivityForResult(intent, CAMERA_RECEIPTREQUEST);
}
Use the code below to display the captured image.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode)
{
case CAMERA_RECEIPTREQUEST:
if(resultCode== Activity.RESULT_OK)
{
if(data!=null)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
ImageView jpgView = (ImageView)findViewById(R.id.imageView1);
Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);
jpgView.setImage(receipt);
}
}
}
source
share