Android Image不保存到SD卡

时间:2013-05-21 07:58:25

标签: android camera android-camera

按下捕获Button后,图像应保存在SD卡中,它正在拍摄快照但不保存图像, 那我怎么能把捕捉按钮放在我想要的任何地方?我在Imageview中有一个叠加层,我需要将按钮放在叠加层上。

3 个答案:

答案 0 :(得分:1)

int picture callback,像这样使用

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");
        }
    };

答案 1 :(得分:1)

使用此选项将图像存储在SD卡中

     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();
            }
}

答案 2 :(得分:0)

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();   

以这种方式更改上述代码段:

    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()