Android: Getting file name from camera?

前端 未结 3 714
耶瑟儿~
耶瑟儿~ 2020-12-28 23:31

I ran into an issue with something that I am probably just overlooking.

I want to take a picture from the surface preview of the camera, and save it to the sd_

相关标签:
3条回答
  • 2020-12-29 00:04

    it doesn't save image? in my app this code saves image, maybe you use variable "filaname" to get image from sdcard? to use image from sdcard is better to save in variable, for examople, "fileUri" value of uri.toString, end get from sdcard file with uri Uri.parse(fileUri)..

    0 讨论(0)
  • 2020-12-29 00:04

    Hope this helps / Probably not the best way to go about it, but it worked. Here you go:
    This is the camera capture image callback.

    public class ImageCaptureCallback implements PictureCallback {
    
        private OutputStream filoutputStream;
        public ImageCaptureCallback(OutputStream filoutputStream) {
            this.filoutputStream = filoutputStream;
        }
    
        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
    
            try {
                Log.v(getClass().getSimpleName(), "onPictureTaken=" + data + " length = " + data.length);
                FileOutputStream buf = new FileOutputStream("/sdcard/dcim/Camera/" + CameraActivity.filename + ".jpg");
                buf.write(data);
                buf.flush();
                buf.close();
                // filoutputStream.write(data);
                filoutputStream.flush();
                filoutputStream.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-29 00:11

    This was resolved by implementing PictureCallback via a ImageCaptureCallback class, and Overriding the onPictureTaken where the file was being written via a file output stream. All you had to do was change the fileoutput stream to the filename you want.

    0 讨论(0)
提交回复
热议问题