3

请帮忙,

我目前将图像上传到我的网络服务,在上传时确实附有 EXIF 数据。当它到达服务器时,它减去它的 exif 数据。

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

在我上传图像之前,它会存储到设备 SD 卡中,然后使用 BitmapFactory 类对其进行解码。

我在想它在图像压缩过程中丢失了,有人有解决方案或想法吗?

谢谢

地洞111

4

4 回答 4

4

EXIF 数据在编码期间被剥离。但是,ExifInterface将允许您在压缩文件上设置 EXIF 数据。不幸的是,您需要压缩图像,将其写入文件,然后在文件上设置 EXIF,最后上传。

于 2013-08-22T12:43:38.767 回答
1

我这样做是为了让其他人不必经历单调......

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){}
    }
于 2015-08-20T18:52:07.607 回答
0

我知道这个问题很老,但我必须编写一个方法来在 Kotlin 中复制 exif 数据,我认为它可能对其他人有帮助。

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()
        }
    }
}
于 2020-03-31T14:07:45.070 回答
0

使用ImageDecoder API 而不是BitmapFactory.decodeFile. 它没有省略exif。

val source: ImageDecoder.Source = ImageDecoder.createSource(file)
val outBitmap: Bitmap = ImageDecoder.decodeBitmap(source)
于 2021-06-23T16:36:06.063 回答