TSGames
TSGames

Reputation: 679

Get current shutter speed/iso on android

I know there are a lot of questions which asking if you can set shutter speed/iso etc. and it doesn't seems to be possible...

BUT, is it at least possible to get values like shutter speed, aperture and iso? (without taking a picture first and scanning for the exif values...)

I mean like some kind of a live preview of the values currently set by the system/hardware.

Upvotes: 2

Views: 6237

Answers (3)

Eddy Talvala
Eddy Talvala

Reputation: 18117

With camera2, you can look at the CaptureResult objects produced via the onCaptureCompleted callback.

If the device supports the READ_SENSOR_SETTINGS capability, then the CaptureResult SENSOR_EXPOSURE_TIME and SENSOR_SENSITIVITY fields will have the current values for exposure and gain selected by the auto-exposure routine.

Otherwise, you'll need to capture a JPEG image and look at its EXIF as described by the other answers.

Upvotes: 3

Thracian
Thracian

Reputation: 66869

You can set shutter speed and exposure time using Camera2 Api i suppose, i don't know much about it. But, it's possible to read exif data from byte[] data you get from camera when picture is taken.

If anyone wish to get current, not the one set using Camera1 Api or Camera2, ISO, exposure time and shutter speed values. For Camera1 Api write data to FileOutputStream and read exif data using ExifInterface. You can get every meta-data written to byte using this method. After getting data you can dispose of that file and compress image to png or jpg using Bitmap.compress();

     private PictureCallback mPicture = new PictureCallback() {

            @Override
            public void onPictureTaken(byte[] data, Camera camera) {
                long startTime = System.currentTimeMillis();

                File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
                FileOutputStream fos = null;
                Bitmap bitmap = null;

                if (pictureFile == null) {
                    return;
                }

                try {
                    fos = new FileOutputStream(pictureFile);
                    // TODO Writes Exif Data to image
                    System.out.println("************ EXIF ************");
                    fos.write(data);
                    ExifInterface exifInterface = new ExifInterface(pictureFile.getAbsolutePath());
                    String model = exifInterface.getAttribute(ExifInterface.TAG_MODEL);
                    String make = exifInterface.getAttribute(ExifInterface.TAG_MAKE);
                    String flash = exifInterface.getAttribute(ExifInterface.TAG_FLASH);
                    String exposureMode = exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_MODE);

                    String focalLengthString = exifInterface.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
                    String isoString = exifInterface.getAttribute(ExifInterface.TAG_ISO_SPEED_RATINGS);
                    String apertureString = exifInterface.getAttribute(ExifInterface.TAG_APERTURE_VALUE);
                    String exposureTimeString = exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
                    String shutterSpeedString = exifInterface.getAttribute(ExifInterface.TAG_SHUTTER_SPEED_VALUE);

                    Double focalLength = exifInterface.getAttributeDouble(ExifInterface.TAG_FOCAL_LENGTH, 0);
                    Double iso = exifInterface.getAttributeDouble(ExifInterface.TAG_ISO_SPEED_RATINGS, 0);
                    Double aperture = exifInterface.getAttributeDouble(ExifInterface.TAG_APERTURE_VALUE, 0);
                    Double exposureTime = exifInterface.getAttributeDouble(ExifInterface.TAG_EXPOSURE_TIME, 0);
                    Double shutterSpeed = exifInterface.getAttributeDouble(ExifInterface.TAG_SHUTTER_SPEED_VALUE, 0);

                    System.out.println("CameraActivity model " + model);
                    System.out.println("CameraActivity make " + make);
                    System.out.println("CameraActivity flash " + flash);
                    System.out.println("CameraActivity exposureMode " + exposureMode);
                    System.out.println("CameraActivity focalLengthString " + focalLengthString + ", focalLength " + focalLength);
                    System.out.println("CameraActivity isoString " + isoString + ", iso " + iso);
                    System.out.println("CameraActivity apertureString " + apertureString + ", aperture " + aperture);
                    System.out.println("CameraActivity exposureTimeString " + exposureTimeString + ", exposureTime " + exposureTime);
                    System.out.println("CameraActivity shutterSpeedString " + shutterSpeedString + ", shutterSpeed " + shutterSpeed);

                    System.out.println("************ EXIF ************");

                } catch (FileNotFoundException e) {
                    System.out.println("CameraActivity onPictureTaken() File not found: " + e.getMessage());
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        if (fos != null) {
                            fos.close();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(pictureFile)));
                    fos = null;
                    pictureFile = null;

}

These are the results i get for my my device

 ************ EXIF ************
CameraActivity model General Mobile 4G Dual
CameraActivity make General Mobile
CameraActivity flash 24
CameraActivity exposureMode 0
CameraActivity focalLengthString 1150/1000, focalLength 1.15
CameraActivity isoString 262, iso 262.0
CameraActivity apertureString 260/100, aperture 2.6
CameraActivity exposureTimeString 0.03333333333333333, exposureTime 0.03333333333333333
CameraActivity shutterSpeedString 4906/1000, shutterSpeed 4.906

Upvotes: 1

Dima Bobby
Dima Bobby

Reputation: 1

Regarding iso value, see this question Android Camera API ISO Setting?, regarding shutter refer to this post https://stackoverflow.com/a/3550573/1860199

Upvotes: 0

Related Questions