0

Hi am capturing an image through camera intent it works good but my problem is that am not getting preview of that image my requirement is very simple, after clicking of photo through camera it must ask me to SAVE or DISCARD this image if i press SAVE then it get save into sd card thats it...

here is my code

private void openCamera() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    capturedFile = new File(Environment.getExternalStorageDirectory(),
            "tmp_nookster_profilepic"
                    + String.valueOf(System.currentTimeMillis()) + ".jpg");

    mImageCaptureUri = Uri.fromFile(capturedFile);

    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
            mImageCaptureUri);

    try {
        intent.putExtra("return-data", true);

        startActivityForResult(intent, PICK_FROM_CAMERA_NO_CROP);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }








protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK)
        return;

    switch (requestCode) {
    case PICK_FROM_CAMERA_NO_CROP: {
            iu.SaveCapturedImage(BitmapFactory.decodeFile(capturedFile
                    .getAbsolutePath()));
            try {
                if (capturedFile.exists())
                    capturedFile.delete();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

        break;

here "iu" is object of ImageUtility class and "SaveCapturedImage" is method to store that captured image in SdCard

2 Answers2

0

You can get a preview of the captured File as this:

Bitmap getPreview(File image) {
    final int THUMBNAIL_SIZE = 72;
    BitmapFactory.Options bounds = new BitmapFactory.Options();
    bounds.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(image.getPath(), bounds);
    if ((bounds.outWidth == -1) || (bounds.outHeight == -1))
        return null;

    int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight
            : bounds.outWidth;

    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inSampleSize = originalSize / THUMBNAIL_SIZE;
    return BitmapFactory.decodeFile(image.getPath(), opts);
}

then you can show the Bitmap in an ImageView and present the user with Save/Delete buttons.

Axarydax
  • 16,353
  • 21
  • 92
  • 151
0

You have to remove line from your code.

 if (resultCode != RESULT_OK)
    return;

Use following code :

if (resultCode == RESULT_OK) 
    {  
            try
            { 
                Bitmap bitmap=null;
                String imageId = convertImageUriToFile(imageUri,AddRecipes.this);    
                bitmap = BitmapFactory.decodeFile(imageId);
}}


public static String convertImageUriToFile (Uri contentUri, Activity activity)  
{
     String[] proj = { MediaStore.Images.Media.DATA };        
      CursorLoader cursorLoader = new CursorLoader(activity.getApplicationContext(),contentUri, proj, null, null, null);        
      Cursor cursor = cursorLoader.loadInBackground();        
      int column_index =  cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      cursor.moveToFirst();
      return cursor.getString(column_index);
 }
Devganiya Hitesh
  • 1,207
  • 2
  • 17
  • 31