0

Hi i am using a camera application in android. In my application, I want to save the photo that clicked to device's internal storage(in res folder) and also want to share it. I tried the code as shown bellow.

Camera.PictureCallback jpegCallback = new PictureCallback() 
    {
        public void onPictureTaken(byte[] data, Camera camera) 
        {
            FileOutputStream outStream = null;
            try 
            {               
                outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis()));  
                outStream.write(data);
                outStream.close();
                sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
                Log.d(TAG, "on pictureTaken" + data.length);
            } 
            catch (FileNotFoundException e) 
            {
                e.printStackTrace();
            } 
            catch (IOException e)
            {
                e.printStackTrace();
            } 
            finally
            {}
            setContentView(R.layout.main2);         
            BitmapFactory.Options opts = new BitmapFactory.Options();
            Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,opts);
            imgView = (ImageView)findViewById(R.id.photoResultView);
            imgView.setImageBitmap(bitmap);    
            upload = (Button) findViewById(R.id.upload);
            upload.setOnClickListener(new OnClickListener() 
            {
                public void onClick(View v) 
                {
                    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                    Uri screenshotUri = Uri.parse("/sdcard/%d.jpg");

                    sharingIntent.setType("image/jpg");
                    sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
                    startActivity(Intent.createChooser(sharingIntent, "Share image using"));
                }
            });
        }
    };

if anyone knows about it help me..

Binesh
  • 117
  • 3
  • 15

1 Answers1

0

You can't store images or picture taken from Camera to drawable folder, you can store them to SDCard rather. You can check this link.

UPDATE

You can save the Image taken using this,

File myFile = new File(Environment.getExternalStorageDirectory()+File.separator+"my_image.jpg");
                try {
                    myFile.createNewFile();
                    FileOutputStream outputStream = new FileOutputStream(myFile);
                    outputStream.write(data);
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
Community
  • 1
  • 1
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
  • Hi Lalit Poptani, im trying to save the image to sdcard and share it as shown above. But i can't save it. Therefor I need to save it in internal storage and share from there. Could u help me, if u know about it.. – Binesh Nov 26 '11 at 11:00
  • I had added the stuff to save image to sdcard, you can check it. – Lalit Poptani Nov 26 '11 at 11:39