简体   繁体   English

Android Image不保存到SD卡

[英]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? 按下捕获Button ,图像应保存在SD卡中,它正在拍摄快照但不保存图像,那么如何将捕获按钮放在我想要的任何地方? I have an overlay in the Imageview and I need to put the button over the overlay. 我在Imageview有一个叠加层,我需要将按钮放在叠加层上。

int picture callback, use like this int图片回调,请使用这样的

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 使用此选项将图像存储在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();
            }
}
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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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