Java Code Examples for android.support.media.ExifInterface#saveAttributes()

The following examples show how to use android.support.media.ExifInterface#saveAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From ActivityDiary with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        if(mCurrentPhotoPath != null && viewModel.getCurrentDiaryUri() != null) {
            Uri photoURI = FileProvider.getUriForFile(MainActivity.this,
                    BuildConfig.APPLICATION_ID + ".fileprovider",
                    new File(mCurrentPhotoPath));
            ContentValues values = new ContentValues();
            values.put(ActivityDiaryContract.DiaryImage.URI, photoURI.toString());
            values.put(ActivityDiaryContract.DiaryImage.DIARY_ID, viewModel.getCurrentDiaryUri().getLastPathSegment());

            mQHandler.startInsert(0,
                    null,
                    ActivityDiaryContract.DiaryImage.CONTENT_URI,
                    values);

            if(PreferenceManager
                    .getDefaultSharedPreferences(ActivityDiaryApplication.getAppContext())
                    .getBoolean(SettingsActivity.KEY_PREF_TAG_IMAGES, true)) {
                try {
                    ExifInterface exifInterface = new ExifInterface(mCurrentPhotoPath);
                    if (viewModel.currentActivity().getValue() != null) {
                        /* TODO: #24: when using hierarchical activities tag them all here, seperated with comma */
                        /* would be great to use IPTC keywords instead of EXIF UserComment, but
                         * at time of writing (2017-11-24) it is hard to find a library able to write IPTC
                         * to JPEG for android.
                         * pixymeta-android or apache/commons-imaging could be interesting for this.
                         * */
                        exifInterface.setAttribute(ExifInterface.TAG_USER_COMMENT, viewModel.currentActivity().getValue().getName());
                        exifInterface.saveAttributes();
                    }
                } catch (IOException e) {
                    Log.e(TAG, "writing exif data to " + mCurrentPhotoPath + " failed", e);
                }
            }
        }
    }
}
 
Example 2
Source File: ExifUtil.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
public static void saveExifData(String path, ExifItem[] exifData) {
    try {
        ExifInterface exif = new ExifInterface(path);
        for (int i = 0; i < exifData.length; i++) {
            ExifItem exifItem = exifData[i];
            exif.setAttribute(exifItem.getTag(), exifItem.getValue());
        }
        exif.saveAttributes();
    } catch (IOException | IllegalArgumentException e) {
        e.printStackTrace();
    }
}
 
Example 3
Source File: Util.java    From CVScanner with GNU General Public License v3.0 5 votes vote down vote up
public static boolean setExifRotation(Context context, Uri imageUri, int rotation) throws IOException {
    if (imageUri == null) return false;

    InputStream destStream = null;
    try{
        destStream = context.getContentResolver().openInputStream(imageUri);

        ExifInterface exif = new ExifInterface(destStream);

        exif.setAttribute("UserComment", "Generated using CVScanner");

        int orientation = ExifInterface.ORIENTATION_NORMAL;
        switch (rotation){
            case 1:
                orientation = ExifInterface.ORIENTATION_ROTATE_90;
                break;

            case 2:
                orientation = ExifInterface.ORIENTATION_ROTATE_180;
                break;

            case 3:
                orientation = ExifInterface.ORIENTATION_ROTATE_270;
                break;
        }
        exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(orientation));
        exif.saveAttributes();
    }finally {
        closeSilently(destStream);
    }
    return true;
}