0

I want to use default camera and capture image. i want save image in sdcard/photofolder/ and save filename as curenttime format in sdcard/photofolder/ also display capture image in imageview page

Uri outputFileUri = Uri.fromFile("/sdcard/Photofolder/");    
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, CAMERA_REQUEST);

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
            if (requestCode == CAMERA_REQUEST) {  
                Bitmap photo = (Bitmap) data.getExtras().get("data"); 
               // imageView.setImageBitmap(photo);

                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 4;
                Bitmap bitmap = BitmapFactory.decodeFile(picFileName, options);
                imageView.setImageBitmap(bitmap);
                imageView.setVisibility(View.VISIBLE);

            }  
        }

any idea about this ?? thanks in adavance

user370305
  • 108,599
  • 23
  • 164
  • 151
ckpatel
  • 1,926
  • 4
  • 18
  • 34

6 Answers6

2

You can get SDCard path like..

String root = Environment.getExternalStorageDirectory().toString();

new File(root + "/photofolder").mkdirs();

Then you can save a file to root + "/photofolder/20120830025700.jpg".


Have you requested permission to write onto SD card? Add the following string to you app manifest:

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Saurabh Vardani
  • 1,821
  • 2
  • 18
  • 33
Manoj Manani
  • 507
  • 4
  • 9
0

below code can help u

    private void takePicture() 
        {   cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, IMAGE_CAPTURE);
        }

 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (requestCode == CAMERA_REQUEST) {   
     File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
     File output = new File(dir, "camerascript.png");
     }  
}
Hardik Nadiyapara
  • 2,436
  • 2
  • 17
  • 24
  • thanks brother but i want to save image in sdcard/photofolder/ and save image as currenttime format like example sdcard/photofolder/20120830025700.jpg – ckpatel Aug 30 '12 at 09:24
0

As example given here try this code...

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File output = new File(dir,"camera.png");

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(output));
String path =output.getAbsolutePath();
startActivityForResult(cameraIntent, TAKE_PHOTO);

path will return location of your image in sdcard

MAC
  • 15,799
  • 8
  • 54
  • 95
0

Use this code to save image into SDcard and also create 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);   
       }  

To display the captured image use the below code

 @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);
 }
 }
 }
vinothp
  • 9,939
  • 19
  • 61
  • 103
0

Try this

private void cameraOn() {
            tempUri = "sdcard/......";
        i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        i.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);
        startActivityForResult(i, cameraData);
    }

To get the bitmap

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
        case cameraData:
            if (resultCode == RESULT_OK) {
                Bitmap bmp = BitmapFactory.decodeFile(tempUri.getPath(), null);
                imageShow.setImageBitmap(bmp);
            } 
            break;
        }
    }
Sieryuu
  • 1,510
  • 2
  • 16
  • 41
0

try using this in onActivityResult()

setupImage(photo);

and

public Bitmap setupImage(Intent data) { 
      BitmapFactory.Options options = new BitmapFactory.Options(); 
      options.inSampleSize = SAMPLE_SIZE;     // SAMPLE_SIZE = 2 

      Bitmap tempBitmap = null; 
      Bitmap bm = null; 
      try { 
       tempBitmap = (Bitmap) data.getExtras().get("data");
        bm = tempBitmap; 

        Log.v("ManageImage-hero", "the data.getData seems to be valid"); 

        FileOutputStream out = new FileOutputStream(outputFileUri.getPath()); 
        tempBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); 
      } catch (NullPointerException ex) { 
        Log.v("ManageImage-other", "another phone type"); 
        bm = otherImageProcessing(options); 
      } catch(Exception e) { 
        Log.v("ManageImage-setupImage", "problem setting up the image"+e); 
      } 

      return bm; 
    } 
private Bitmap otherImageProcessing(BitmapFactory.Options options) { 
      Bitmap bm = null; 

      try { 
        FileInputStream fis = new FileInputStream(outputFileUri.getPath()); 
        BufferedInputStream bis = new BufferedInputStream(fis); 
        bm = BitmapFactory.decodeStream(bis, null, options); 

        // cleaning up 
        fis.close(); 
        bis.close(); 
      } catch(Exception e) { 
        Log.e("ManageImage-otherImageProcessing", "Cannot load image", e); 
      } 

      return bm; 
    } 
G_S
  • 7,068
  • 2
  • 21
  • 51