简体   繁体   中英

Android Image Not saving to sdcard

After pressing capture Button , image should save in sdcard, it is taking snapshot but not saving the image with that, Then how can I put the capture button wherever I want? I have an overlay in the Imageview and I need to put the button over the overlay.

int picture callback, use like this

jpegCallback = new PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {
            camera.startPreview();
            FileOutputStream outStream = null;
            try {
                outStream = new FileOutputStream(
                        "/mnt/sdcard/myphoto.jpg");
                outStream.write(data);
                outStream.close();
                Log.d("Log", "onPictureTaken - wrote bytes: " + data.length);
            } catch (FileNotFoundException e) {
                e.printStackTrace();

            } catch (IOException e) {
                e.printStackTrace();
            } finally {

            }
            Log.d("Log", "onPictureTaken - jpeg");
        }
    };

Use this one to store image in sd card

     public void save(Bitmap image)
                     {
            File sdcard = Environment.getExternalStorageDirectory();
            File f = new File (sdcard, imagename);
            FileOutputStream out=null;
            try {
                out = new FileOutputStream(f);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            image.compress(Bitmap.CompressFormat.PNG, 90, out);
            try {
                out.flush();
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
}
stream=new ByteArrayOutputStream();
temBitmap=Bitmap.createBitmap(bmp);
temBitmap.compress(Bitmap.CompressFormat.JPEG,100, stream);
 path+=String.format(
                getString(R.string._sdcard_d_jpg),
                System.currentTimeMillis());
  outStream = new FileOutputStream(path+extension); // <9>
  outStream.write(stream.toByteArray());
  outStream.close();   

change the above snippet this way:

    path+=String.format(
            getString(R.string._sdcard_d_jpg),
            System.currentTimeMillis());
    outStream = new FileOutputStream(path+extension); // <9>
    temBitmap=Bitmap.createBitmap(bmp);
    temBitmap.compress(Bitmap.CompressFormat.JPEG,100, outStream);
    outStream.close();     
     temBitmap.recycle()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM