简体   繁体   中英

Android: Image upload to web-service loses EXIF data

Please help,

I currently upload an image to my web-service which does have the EXIF data attached to it at time of upload. When it arrives on the server, it is minus it's exif data.

  Bitmap bmp = BitmapFactory.decodeFile(fullFileName);
                  if (bmp == null) {
                    //oh sugar, not cool
                     continue;
                }
                  ByteArrayOutputStream stream = new ByteArrayOutputStream();
                  bmp.compress(Bitmap.CompressFormat.JPEG, 60, stream);
                  byte[] byteArray = stream.toByteArray();


                DefaultHttpClient client = new DefaultHttpClient();
                HttpPost post = new HttpPost("webserviceurl");
                ByteArrayEntity test = new ByteArrayEntity(byteArray){...}

     post.setEntity(test);   

Before I upload the image, it's stored to the devices SD card to which is then decoded using the BitmapFactory class.

I'm thinking its during the image compression that its lost, anybody got a solution or idea ?

Thanks

Burrows111

EXIF data is stripped during encode. However, ExifInterface will allow you to set the EXIF data on the compressed file. Unfortunately, you'll need to compress the image, write it to a file, then set the EXIF on the file, and finally upload that.

I made this so others don't have to go through the monotony...

public static void copyExifData(String file1, String file2){
        try {
            ExifInterface file1Exif = new ExifInterface(file1);
            ExifInterface file2Exif = new ExifInterface(file2);

            String aperture = file1Exif.getAttribute(ExifInterface.TAG_APERTURE);
            String dateTime = file1Exif.getAttribute(ExifInterface.TAG_DATETIME);
            String exposureTime = file1Exif.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
            String flash = file1Exif.getAttribute(ExifInterface.TAG_FLASH);
            String focalLength = file1Exif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
            String gpsAltitude = file1Exif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE);
            String gpsAltitudeRef = file1Exif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF);
            String gpsDateStamp = file1Exif.getAttribute(ExifInterface.TAG_GPS_DATESTAMP);
            String gpsLatitude = file1Exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
            String gpsLatitudeRef = file1Exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
            String gpsLongitude = file1Exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
            String gpsLongitudeRef = file1Exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
            String gpsProcessingMethod = file1Exif.getAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD);
            String gpsTimestamp = file1Exif.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP);
            Integer imageLength = file1Exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0);
            Integer imageWidth = file1Exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0);
            String iso = file1Exif.getAttribute(ExifInterface.TAG_ISO);
            String make = file1Exif.getAttribute(ExifInterface.TAG_MAKE);
            String model = file1Exif.getAttribute(ExifInterface.TAG_MODEL);
            Integer orientation = file1Exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
            Integer whiteBalance = file1Exif.getAttributeInt(ExifInterface.TAG_WHITE_BALANCE, 0);


            file2Exif.setAttribute(ExifInterface.TAG_ORIENTATION, orientation.toString());
            file2Exif.setAttribute(ExifInterface.TAG_APERTURE, aperture);
            file2Exif.setAttribute(ExifInterface.TAG_DATETIME, dateTime);
            file2Exif.setAttribute(ExifInterface.TAG_EXPOSURE_TIME, exposureTime);
            file2Exif.setAttribute(ExifInterface.TAG_FLASH, flash);
            file2Exif.setAttribute(ExifInterface.TAG_FOCAL_LENGTH, focalLength);
            file2Exif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE, gpsAltitude);
            file2Exif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF, gpsAltitudeRef);
            file2Exif.setAttribute(ExifInterface.TAG_GPS_DATESTAMP, gpsDateStamp);
            file2Exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, gpsLatitude);
            file2Exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, gpsLatitudeRef);
            file2Exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, gpsLongitude);
            file2Exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, gpsLongitudeRef);
            file2Exif.setAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD, gpsProcessingMethod);
            file2Exif.setAttribute(ExifInterface.TAG_GPS_TIMESTAMP, gpsTimestamp);
            file2Exif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, imageLength.toString());
            file2Exif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, imageWidth.toString());
            file2Exif.setAttribute(ExifInterface.TAG_ISO, iso);
            file2Exif.setAttribute(ExifInterface.TAG_MAKE, make);
            file2Exif.setAttribute(ExifInterface.TAG_MODEL, model);
            file2Exif.setAttribute(ExifInterface.TAG_WHITE_BALANCE, whiteBalance.toString());
            file2Exif.saveAttributes();
        }
        catch (FileNotFoundException io) {}
        catch (IOException io) {}
        catch (NullPointerException np){}
    }

I know the question is old but I had to write a method to copy exif data in Kotlin and I thought it might be helpful to others.

import androidx.exifinterface.media.ExifInterface

class ExifUtils {

    companion object {

        fun copyExif(src: ExifInterface, dest: ExifInterface) {

            dest.setAttribute(ExifInterface.TAG_APERTURE_VALUE, src.getAttribute(ExifInterface.TAG_APERTURE_VALUE))
            dest.setAttribute(ExifInterface.TAG_ARTIST, src.getAttribute(ExifInterface.TAG_ARTIST))
            dest.setAttribute(ExifInterface.TAG_BITS_PER_SAMPLE, src.getAttribute(ExifInterface.TAG_BITS_PER_SAMPLE))
            dest.setAttribute(ExifInterface.TAG_BODY_SERIAL_NUMBER, src.getAttribute(ExifInterface.TAG_BODY_SERIAL_NUMBER))
            dest.setAttribute(ExifInterface.TAG_BRIGHTNESS_VALUE, src.getAttribute(ExifInterface.TAG_BRIGHTNESS_VALUE))
            dest.setAttribute(ExifInterface.TAG_CAMERA_OWNER_NAME, src.getAttribute(ExifInterface.TAG_CAMERA_OWNER_NAME))
            dest.setAttribute(ExifInterface.TAG_CFA_PATTERN, src.getAttribute(ExifInterface.TAG_CFA_PATTERN))
            dest.setAttribute(ExifInterface.TAG_COLOR_SPACE, src.getAttribute(ExifInterface.TAG_COLOR_SPACE))
            dest.setAttribute(ExifInterface.TAG_COMPONENTS_CONFIGURATION, src.getAttribute(ExifInterface.TAG_COMPONENTS_CONFIGURATION))
            dest.setAttribute(ExifInterface.TAG_COMPRESSED_BITS_PER_PIXEL, src.getAttribute(ExifInterface.TAG_COMPRESSED_BITS_PER_PIXEL))
            dest.setAttribute(ExifInterface.TAG_COMPRESSION, src.getAttribute(ExifInterface.TAG_COMPRESSION))
            dest.setAttribute(ExifInterface.TAG_CONTRAST, src.getAttribute(ExifInterface.TAG_CONTRAST))
            dest.setAttribute(ExifInterface.TAG_COPYRIGHT, src.getAttribute(ExifInterface.TAG_COPYRIGHT))
            dest.setAttribute(ExifInterface.TAG_CUSTOM_RENDERED, src.getAttribute(ExifInterface.TAG_CUSTOM_RENDERED))
            dest.setAttribute(ExifInterface.TAG_DATETIME, src.getAttribute(ExifInterface.TAG_DATETIME))
            dest.setAttribute(ExifInterface.TAG_DATETIME_DIGITIZED, src.getAttribute(ExifInterface.TAG_DATETIME_DIGITIZED))
            dest.setAttribute(ExifInterface.TAG_DATETIME_ORIGINAL, src.getAttribute(ExifInterface.TAG_DATETIME_ORIGINAL))
            dest.setAttribute(ExifInterface.TAG_DEFAULT_CROP_SIZE, src.getAttribute(ExifInterface.TAG_DEFAULT_CROP_SIZE))
            dest.setAttribute(ExifInterface.TAG_DEVICE_SETTING_DESCRIPTION, src.getAttribute(ExifInterface.TAG_DEVICE_SETTING_DESCRIPTION))
            dest.setAttribute(ExifInterface.TAG_DIGITAL_ZOOM_RATIO, src.getAttribute(ExifInterface.TAG_DIGITAL_ZOOM_RATIO))
            dest.setAttribute(ExifInterface.TAG_DNG_VERSION, src.getAttribute(ExifInterface.TAG_DNG_VERSION))
            dest.setAttribute(ExifInterface.TAG_EXIF_VERSION, src.getAttribute(ExifInterface.TAG_EXIF_VERSION))
            dest.setAttribute(ExifInterface.TAG_EXPOSURE_BIAS_VALUE, src.getAttribute(ExifInterface.TAG_EXPOSURE_BIAS_VALUE))
            dest.setAttribute(ExifInterface.TAG_EXPOSURE_INDEX, src.getAttribute(ExifInterface.TAG_EXPOSURE_INDEX))
            dest.setAttribute(ExifInterface.TAG_EXPOSURE_MODE, src.getAttribute(ExifInterface.TAG_EXPOSURE_MODE))
            dest.setAttribute(ExifInterface.TAG_EXPOSURE_PROGRAM, src.getAttribute(ExifInterface.TAG_EXPOSURE_PROGRAM))
            dest.setAttribute(ExifInterface.TAG_EXPOSURE_TIME, src.getAttribute(ExifInterface.TAG_EXPOSURE_TIME))
            dest.setAttribute(ExifInterface.TAG_FILE_SOURCE, src.getAttribute(ExifInterface.TAG_FILE_SOURCE))
            dest.setAttribute(ExifInterface.TAG_FLASH, src.getAttribute(ExifInterface.TAG_FLASH))
            dest.setAttribute(ExifInterface.TAG_FLASHPIX_VERSION, src.getAttribute(ExifInterface.TAG_FLASHPIX_VERSION))
            dest.setAttribute(ExifInterface.TAG_FLASH_ENERGY, src.getAttribute(ExifInterface.TAG_FLASH_ENERGY))
            dest.setAttribute(ExifInterface.TAG_FOCAL_LENGTH, src.getAttribute(ExifInterface.TAG_FOCAL_LENGTH))
            dest.setAttribute(ExifInterface.TAG_FOCAL_LENGTH_IN_35MM_FILM, src.getAttribute(ExifInterface.TAG_FOCAL_LENGTH_IN_35MM_FILM))
            dest.setAttribute(ExifInterface.TAG_FOCAL_PLANE_RESOLUTION_UNIT, src.getAttribute(ExifInterface.TAG_FOCAL_PLANE_RESOLUTION_UNIT))
            dest.setAttribute(ExifInterface.TAG_FOCAL_PLANE_X_RESOLUTION, src.getAttribute(ExifInterface.TAG_FOCAL_PLANE_X_RESOLUTION))
            dest.setAttribute(ExifInterface.TAG_FOCAL_PLANE_Y_RESOLUTION, src.getAttribute(ExifInterface.TAG_FOCAL_PLANE_Y_RESOLUTION))
            dest.setAttribute(ExifInterface.TAG_F_NUMBER, src.getAttribute(ExifInterface.TAG_F_NUMBER))
            dest.setAttribute(ExifInterface.TAG_GAIN_CONTROL, src.getAttribute(ExifInterface.TAG_GAIN_CONTROL))
            dest.setAttribute(ExifInterface.TAG_GAMMA, src.getAttribute(ExifInterface.TAG_GAMMA))
            dest.setAttribute(ExifInterface.TAG_GPS_ALTITUDE, src.getAttribute(ExifInterface.TAG_GPS_ALTITUDE))
            dest.setAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF, src.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF))
            dest.setAttribute(ExifInterface.TAG_GPS_AREA_INFORMATION, src.getAttribute(ExifInterface.TAG_GPS_AREA_INFORMATION))
            dest.setAttribute(ExifInterface.TAG_GPS_DATESTAMP, src.getAttribute(ExifInterface.TAG_GPS_DATESTAMP))
            dest.setAttribute(ExifInterface.TAG_GPS_DEST_BEARING, src.getAttribute(ExifInterface.TAG_GPS_DEST_BEARING))
            dest.setAttribute(ExifInterface.TAG_GPS_DEST_BEARING_REF, src.getAttribute(ExifInterface.TAG_GPS_DEST_BEARING_REF))
            dest.setAttribute(ExifInterface.TAG_GPS_DEST_DISTANCE, src.getAttribute(ExifInterface.TAG_GPS_DEST_DISTANCE))
            dest.setAttribute(ExifInterface.TAG_GPS_DEST_DISTANCE_REF, src.getAttribute(ExifInterface.TAG_GPS_DEST_DISTANCE_REF))
            dest.setAttribute(ExifInterface.TAG_GPS_DEST_LATITUDE, src.getAttribute(ExifInterface.TAG_GPS_DEST_LATITUDE))
            dest.setAttribute(ExifInterface.TAG_GPS_DEST_LATITUDE_REF, src.getAttribute(ExifInterface.TAG_GPS_DEST_LATITUDE_REF))
            dest.setAttribute(ExifInterface.TAG_GPS_DEST_LONGITUDE, src.getAttribute(ExifInterface.TAG_GPS_DEST_LONGITUDE))
            dest.setAttribute(ExifInterface.TAG_GPS_DEST_LONGITUDE_REF, src.getAttribute(ExifInterface.TAG_GPS_DEST_LONGITUDE_REF))
            dest.setAttribute(ExifInterface.TAG_GPS_DIFFERENTIAL, src.getAttribute(ExifInterface.TAG_GPS_DIFFERENTIAL))
            dest.setAttribute(ExifInterface.TAG_GPS_DOP, src.getAttribute(ExifInterface.TAG_GPS_DOP))
            dest.setAttribute(ExifInterface.TAG_GPS_H_POSITIONING_ERROR, src.getAttribute(ExifInterface.TAG_GPS_H_POSITIONING_ERROR))
            dest.setAttribute(ExifInterface.TAG_GPS_IMG_DIRECTION, src.getAttribute(ExifInterface.TAG_GPS_IMG_DIRECTION))
            dest.setAttribute(ExifInterface.TAG_GPS_IMG_DIRECTION_REF, src.getAttribute(ExifInterface.TAG_GPS_IMG_DIRECTION_REF))
            dest.setAttribute(ExifInterface.TAG_GPS_LATITUDE, src.getAttribute(ExifInterface.TAG_GPS_LATITUDE))
            dest.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, src.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF))
            dest.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, src.getAttribute(ExifInterface.TAG_GPS_LONGITUDE))
            dest.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, src.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF))
            dest.setAttribute(ExifInterface.TAG_GPS_MAP_DATUM, src.getAttribute(ExifInterface.TAG_GPS_MAP_DATUM))
            dest.setAttribute(ExifInterface.TAG_GPS_MEASURE_MODE, src.getAttribute(ExifInterface.TAG_GPS_MEASURE_MODE))
            dest.setAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD, src.getAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD))
            dest.setAttribute(ExifInterface.TAG_GPS_SATELLITES, src.getAttribute(ExifInterface.TAG_GPS_SATELLITES))
            dest.setAttribute(ExifInterface.TAG_GPS_SPEED, src.getAttribute(ExifInterface.TAG_GPS_SPEED))
            dest.setAttribute(ExifInterface.TAG_GPS_SPEED_REF, src.getAttribute(ExifInterface.TAG_GPS_SPEED_REF))
            dest.setAttribute(ExifInterface.TAG_GPS_STATUS, src.getAttribute(ExifInterface.TAG_GPS_STATUS))
            dest.setAttribute(ExifInterface.TAG_GPS_TIMESTAMP, src.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP))
            dest.setAttribute(ExifInterface.TAG_GPS_TRACK, src.getAttribute(ExifInterface.TAG_GPS_TRACK))
            dest.setAttribute(ExifInterface.TAG_GPS_TRACK_REF, src.getAttribute(ExifInterface.TAG_GPS_TRACK_REF))
            dest.setAttribute(ExifInterface.TAG_GPS_VERSION_ID, src.getAttribute(ExifInterface.TAG_GPS_VERSION_ID))
            dest.setAttribute(ExifInterface.TAG_IMAGE_DESCRIPTION, src.getAttribute(ExifInterface.TAG_IMAGE_DESCRIPTION))
            dest.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, src.getAttribute(ExifInterface.TAG_IMAGE_LENGTH))
            dest.setAttribute(ExifInterface.TAG_IMAGE_UNIQUE_ID, src.getAttribute(ExifInterface.TAG_IMAGE_UNIQUE_ID))
            dest.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, src.getAttribute(ExifInterface.TAG_IMAGE_WIDTH))
            dest.setAttribute(ExifInterface.TAG_INTEROPERABILITY_INDEX, src.getAttribute(ExifInterface.TAG_INTEROPERABILITY_INDEX))
            dest.setAttribute(ExifInterface.TAG_ISO_SPEED, src.getAttribute(ExifInterface.TAG_ISO_SPEED))
            dest.setAttribute(ExifInterface.TAG_ISO_SPEED_LATITUDE_YYY, src.getAttribute(ExifInterface.TAG_ISO_SPEED_LATITUDE_YYY))
            dest.setAttribute(ExifInterface.TAG_ISO_SPEED_LATITUDE_ZZZ, src.getAttribute(ExifInterface.TAG_ISO_SPEED_LATITUDE_ZZZ))
            dest.setAttribute(ExifInterface.TAG_JPEG_INTERCHANGE_FORMAT, src.getAttribute(ExifInterface.TAG_JPEG_INTERCHANGE_FORMAT))
            dest.setAttribute(ExifInterface.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH, src.getAttribute(ExifInterface.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH))
            dest.setAttribute(ExifInterface.TAG_LENS_MAKE, src.getAttribute(ExifInterface.TAG_LENS_MAKE))
            dest.setAttribute(ExifInterface.TAG_LENS_MODEL, src.getAttribute(ExifInterface.TAG_LENS_MODEL))
            dest.setAttribute(ExifInterface.TAG_LENS_SERIAL_NUMBER, src.getAttribute(ExifInterface.TAG_LENS_SERIAL_NUMBER))
            dest.setAttribute(ExifInterface.TAG_LENS_SPECIFICATION, src.getAttribute(ExifInterface.TAG_LENS_SPECIFICATION))
            dest.setAttribute(ExifInterface.TAG_LIGHT_SOURCE, src.getAttribute(ExifInterface.TAG_LIGHT_SOURCE))
            dest.setAttribute(ExifInterface.TAG_MAKE, src.getAttribute(ExifInterface.TAG_MAKE))
            dest.setAttribute(ExifInterface.TAG_MAKER_NOTE, src.getAttribute(ExifInterface.TAG_MAKER_NOTE))
            dest.setAttribute(ExifInterface.TAG_MAX_APERTURE_VALUE, src.getAttribute(ExifInterface.TAG_MAX_APERTURE_VALUE))
            dest.setAttribute(ExifInterface.TAG_METERING_MODE, src.getAttribute(ExifInterface.TAG_METERING_MODE))
            dest.setAttribute(ExifInterface.TAG_MODEL, src.getAttribute(ExifInterface.TAG_MODEL))
            dest.setAttribute(ExifInterface.TAG_NEW_SUBFILE_TYPE, src.getAttribute(ExifInterface.TAG_NEW_SUBFILE_TYPE))
            dest.setAttribute(ExifInterface.TAG_OECF, src.getAttribute(ExifInterface.TAG_OECF))
            dest.setAttribute(ExifInterface.TAG_ORF_ASPECT_FRAME, src.getAttribute(ExifInterface.TAG_ORF_ASPECT_FRAME))
            dest.setAttribute(ExifInterface.TAG_ORF_PREVIEW_IMAGE_LENGTH, src.getAttribute(ExifInterface.TAG_ORF_PREVIEW_IMAGE_LENGTH))
            dest.setAttribute(ExifInterface.TAG_ORF_PREVIEW_IMAGE_START, src.getAttribute(ExifInterface.TAG_ORF_PREVIEW_IMAGE_START))
            dest.setAttribute(ExifInterface.TAG_ORF_THUMBNAIL_IMAGE, src.getAttribute(ExifInterface.TAG_ORF_THUMBNAIL_IMAGE))
            dest.setAttribute(ExifInterface.TAG_ORIENTATION, src.getAttribute(ExifInterface.TAG_ORIENTATION))
            dest.setAttribute(ExifInterface.TAG_PHOTOGRAPHIC_SENSITIVITY, src.getAttribute(ExifInterface.TAG_PHOTOGRAPHIC_SENSITIVITY))
            dest.setAttribute(ExifInterface.TAG_PHOTOMETRIC_INTERPRETATION, src.getAttribute(ExifInterface.TAG_PHOTOMETRIC_INTERPRETATION))
            dest.setAttribute(ExifInterface.TAG_PIXEL_X_DIMENSION, src.getAttribute(ExifInterface.TAG_PIXEL_X_DIMENSION))
            dest.setAttribute(ExifInterface.TAG_PIXEL_Y_DIMENSION, src.getAttribute(ExifInterface.TAG_PIXEL_Y_DIMENSION))
            dest.setAttribute(ExifInterface.TAG_PLANAR_CONFIGURATION, src.getAttribute(ExifInterface.TAG_PLANAR_CONFIGURATION))
            dest.setAttribute(ExifInterface.TAG_PRIMARY_CHROMATICITIES, src.getAttribute(ExifInterface.TAG_PRIMARY_CHROMATICITIES))
            dest.setAttribute(ExifInterface.TAG_RECOMMENDED_EXPOSURE_INDEX, src.getAttribute(ExifInterface.TAG_RECOMMENDED_EXPOSURE_INDEX))
            dest.setAttribute(ExifInterface.TAG_REFERENCE_BLACK_WHITE, src.getAttribute(ExifInterface.TAG_REFERENCE_BLACK_WHITE))
            dest.setAttribute(ExifInterface.TAG_RELATED_SOUND_FILE, src.getAttribute(ExifInterface.TAG_RELATED_SOUND_FILE))
            dest.setAttribute(ExifInterface.TAG_RESOLUTION_UNIT, src.getAttribute(ExifInterface.TAG_RESOLUTION_UNIT))
            dest.setAttribute(ExifInterface.TAG_ROWS_PER_STRIP, src.getAttribute(ExifInterface.TAG_ROWS_PER_STRIP))
            dest.setAttribute(ExifInterface.TAG_RW2_ISO, src.getAttribute(ExifInterface.TAG_RW2_ISO))
            dest.setAttribute(ExifInterface.TAG_RW2_JPG_FROM_RAW, src.getAttribute(ExifInterface.TAG_RW2_JPG_FROM_RAW))
            dest.setAttribute(ExifInterface.TAG_RW2_SENSOR_BOTTOM_BORDER, src.getAttribute(ExifInterface.TAG_RW2_SENSOR_BOTTOM_BORDER))
            dest.setAttribute(ExifInterface.TAG_RW2_SENSOR_LEFT_BORDER, src.getAttribute(ExifInterface.TAG_RW2_SENSOR_LEFT_BORDER))
            dest.setAttribute(ExifInterface.TAG_RW2_SENSOR_RIGHT_BORDER, src.getAttribute(ExifInterface.TAG_RW2_SENSOR_RIGHT_BORDER))
            dest.setAttribute(ExifInterface.TAG_RW2_SENSOR_TOP_BORDER, src.getAttribute(ExifInterface.TAG_RW2_SENSOR_TOP_BORDER))
            dest.setAttribute(ExifInterface.TAG_SAMPLES_PER_PIXEL, src.getAttribute(ExifInterface.TAG_SAMPLES_PER_PIXEL))
            dest.setAttribute(ExifInterface.TAG_SATURATION, src.getAttribute(ExifInterface.TAG_SATURATION))
            dest.setAttribute(ExifInterface.TAG_SCENE_CAPTURE_TYPE, src.getAttribute(ExifInterface.TAG_SCENE_CAPTURE_TYPE))
            dest.setAttribute(ExifInterface.TAG_SCENE_TYPE, src.getAttribute(ExifInterface.TAG_SCENE_TYPE))
            dest.setAttribute(ExifInterface.TAG_SENSING_METHOD, src.getAttribute(ExifInterface.TAG_SENSING_METHOD))
            dest.setAttribute(ExifInterface.TAG_SENSITIVITY_TYPE, src.getAttribute(ExifInterface.TAG_SENSITIVITY_TYPE))
            dest.setAttribute(ExifInterface.TAG_SHARPNESS, src.getAttribute(ExifInterface.TAG_SHARPNESS))
            dest.setAttribute(ExifInterface.TAG_SHUTTER_SPEED_VALUE, src.getAttribute(ExifInterface.TAG_SHUTTER_SPEED_VALUE))
            dest.setAttribute(ExifInterface.TAG_SOFTWARE, src.getAttribute(ExifInterface.TAG_SOFTWARE))
            dest.setAttribute(ExifInterface.TAG_SPATIAL_FREQUENCY_RESPONSE, src.getAttribute(ExifInterface.TAG_SPATIAL_FREQUENCY_RESPONSE))
            dest.setAttribute(ExifInterface.TAG_SPECTRAL_SENSITIVITY, src.getAttribute(ExifInterface.TAG_SPECTRAL_SENSITIVITY))
            dest.setAttribute(ExifInterface.TAG_STANDARD_OUTPUT_SENSITIVITY, src.getAttribute(ExifInterface.TAG_STANDARD_OUTPUT_SENSITIVITY))
            dest.setAttribute(ExifInterface.TAG_STRIP_BYTE_COUNTS, src.getAttribute(ExifInterface.TAG_STRIP_BYTE_COUNTS))
            dest.setAttribute(ExifInterface.TAG_STRIP_OFFSETS, src.getAttribute(ExifInterface.TAG_STRIP_OFFSETS))
            dest.setAttribute(ExifInterface.TAG_SUBFILE_TYPE, src.getAttribute(ExifInterface.TAG_SUBFILE_TYPE))
            dest.setAttribute(ExifInterface.TAG_SUBJECT_AREA, src.getAttribute(ExifInterface.TAG_SUBJECT_AREA))
            dest.setAttribute(ExifInterface.TAG_SUBJECT_DISTANCE, src.getAttribute(ExifInterface.TAG_SUBJECT_DISTANCE))
            dest.setAttribute(ExifInterface.TAG_SUBJECT_DISTANCE_RANGE, src.getAttribute(ExifInterface.TAG_SUBJECT_DISTANCE_RANGE))
            dest.setAttribute(ExifInterface.TAG_SUBJECT_LOCATION, src.getAttribute(ExifInterface.TAG_SUBJECT_LOCATION))
            dest.setAttribute(ExifInterface.TAG_SUBSEC_TIME, src.getAttribute(ExifInterface.TAG_SUBSEC_TIME))
            dest.setAttribute(ExifInterface.TAG_SUBSEC_TIME_DIGITIZED, src.getAttribute(ExifInterface.TAG_SUBSEC_TIME_DIGITIZED))
            dest.setAttribute(ExifInterface.TAG_SUBSEC_TIME_ORIGINAL, src.getAttribute(ExifInterface.TAG_SUBSEC_TIME_ORIGINAL))
            dest.setAttribute(ExifInterface.TAG_THUMBNAIL_IMAGE_LENGTH, src.getAttribute(ExifInterface.TAG_THUMBNAIL_IMAGE_LENGTH))
            dest.setAttribute(ExifInterface.TAG_THUMBNAIL_IMAGE_WIDTH, src.getAttribute(ExifInterface.TAG_THUMBNAIL_IMAGE_WIDTH))
            dest.setAttribute(ExifInterface.TAG_TRANSFER_FUNCTION, src.getAttribute(ExifInterface.TAG_TRANSFER_FUNCTION))
            dest.setAttribute(ExifInterface.TAG_USER_COMMENT, src.getAttribute(ExifInterface.TAG_USER_COMMENT))
            dest.setAttribute(ExifInterface.TAG_WHITE_BALANCE, src.getAttribute(ExifInterface.TAG_WHITE_BALANCE))
            dest.setAttribute(ExifInterface.TAG_WHITE_POINT, src.getAttribute(ExifInterface.TAG_WHITE_POINT))
            dest.setAttribute(ExifInterface.TAG_XMP, src.getAttribute(ExifInterface.TAG_XMP))
            dest.setAttribute(ExifInterface.TAG_X_RESOLUTION, src.getAttribute(ExifInterface.TAG_X_RESOLUTION))
            dest.setAttribute(ExifInterface.TAG_Y_CB_CR_COEFFICIENTS, src.getAttribute(ExifInterface.TAG_Y_CB_CR_COEFFICIENTS))
            dest.setAttribute(ExifInterface.TAG_Y_CB_CR_POSITIONING, src.getAttribute(ExifInterface.TAG_Y_CB_CR_POSITIONING))
            dest.setAttribute(ExifInterface.TAG_Y_CB_CR_SUB_SAMPLING, src.getAttribute(ExifInterface.TAG_Y_CB_CR_SUB_SAMPLING))
            dest.setAttribute(ExifInterface.TAG_Y_RESOLUTION, src.getAttribute(ExifInterface.TAG_Y_RESOLUTION))

            dest.saveAttributes()
        }
    }
}

Use ImageDecoder API instead of BitmapFactory.decodeFile . It doesn't omit exif.

val source: ImageDecoder.Source = ImageDecoder.createSource(file)
val outBitmap: Bitmap = ImageDecoder.decodeBitmap(source)

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