Example usage for android.media ExifInterface TAG_MAKE

List of usage examples for android.media ExifInterface TAG_MAKE

Introduction

In this page you can find the example usage for android.media ExifInterface TAG_MAKE.

Prototype

String TAG_MAKE

To view the source code for android.media ExifInterface TAG_MAKE.

Click Source Link

Document

Type is String.

Usage

From source file:Main.java

public static void removeExif(String path) {
    if (!TextUtils.isEmpty(path)) {
        return;//from   www  . j av a  2s .  c o m
    }
    ExifInterface exifInterface;
    try {
        exifInterface = new ExifInterface(path);
    } catch (IOException ignore) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        exifInterface.setAttribute(ExifInterface.TAG_ARTIST, "");
        exifInterface.setAttribute(ExifInterface.TAG_RESOLUTION_UNIT, "0");
        exifInterface.setAttribute(ExifInterface.TAG_DATETIME_ORIGINAL, "");
        exifInterface.setAttribute(ExifInterface.TAG_MAKER_NOTE, "0");
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        exifInterface.setAttribute(ExifInterface.TAG_DATETIME_DIGITIZED, "");
    }
    exifInterface.setAttribute(ExifInterface.TAG_MAKE, "");
    exifInterface.setAttribute(ExifInterface.TAG_MODEL, "");
    exifInterface.setAttribute(ExifInterface.TAG_ORIENTATION, "0");

    exifInterface.setAttribute(ExifInterface.TAG_DATETIME, "");
    exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE, "");
    exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, "");

    exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE, "");

}

From source file:Main.java

public static void copyExifData(File srcImgFile, File dstImgFile) throws IOException {
    ExifInterface srcExif = new ExifInterface(srcImgFile.getCanonicalPath());
    ExifInterface dstExif = new ExifInterface(dstImgFile.getCanonicalPath());

    int buildSDKVersion = Build.VERSION.SDK_INT;

    // From API 11
    if (buildSDKVersion >= Build.VERSION_CODES.HONEYCOMB) {
        if (srcExif.getAttribute(ExifInterface.TAG_APERTURE) != null) {
            dstExif.setAttribute(ExifInterface.TAG_APERTURE, srcExif.getAttribute(ExifInterface.TAG_APERTURE));
        }/*from ww  w .  jav  a2s. c  om*/
        if (srcExif.getAttribute(ExifInterface.TAG_EXPOSURE_TIME) != null) {
            dstExif.setAttribute(ExifInterface.TAG_EXPOSURE_TIME,
                    srcExif.getAttribute(ExifInterface.TAG_EXPOSURE_TIME));
        }
        if (srcExif.getAttribute(ExifInterface.TAG_ISO) != null) {
            dstExif.setAttribute(ExifInterface.TAG_ISO, srcExif.getAttribute(ExifInterface.TAG_ISO));
        }
    }

    // From API 9
    if (buildSDKVersion >= Build.VERSION_CODES.GINGERBREAD) {
        if (srcExif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE) != null) {
            dstExif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE,
                    srcExif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE));
        }
        if (srcExif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF) != null) {
            dstExif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF,
                    srcExif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF));
        }
    }

    // From API 8
    if (buildSDKVersion >= Build.VERSION_CODES.FROYO) {
        if (srcExif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH) != null) {
            dstExif.setAttribute(ExifInterface.TAG_FOCAL_LENGTH,
                    srcExif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH));
        }
        if (srcExif.getAttribute(ExifInterface.TAG_GPS_DATESTAMP) != null) {
            dstExif.setAttribute(ExifInterface.TAG_GPS_DATESTAMP,
                    srcExif.getAttribute(ExifInterface.TAG_GPS_DATESTAMP));
        }
        if (srcExif.getAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD) != null) {
            dstExif.setAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD,
                    srcExif.getAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD));
        }
        if (srcExif.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP) != null) {
            dstExif.setAttribute(ExifInterface.TAG_GPS_TIMESTAMP,
                    srcExif.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP));
        }
    }

    if (srcExif.getAttribute(ExifInterface.TAG_DATETIME) != null) {
        dstExif.setAttribute(ExifInterface.TAG_DATETIME, srcExif.getAttribute(ExifInterface.TAG_DATETIME));
    }
    if (srcExif.getAttribute(ExifInterface.TAG_FLASH) != null) {
        dstExif.setAttribute(ExifInterface.TAG_FLASH, srcExif.getAttribute(ExifInterface.TAG_FLASH));
    }
    if (srcExif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) != null) {
        dstExif.setAttribute(ExifInterface.TAG_GPS_LATITUDE,
                srcExif.getAttribute(ExifInterface.TAG_GPS_LATITUDE));
    }
    if (srcExif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF) != null) {
        dstExif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF,
                srcExif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF));
    }
    if (srcExif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE) != null) {
        dstExif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,
                srcExif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE));
    }
    if (srcExif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF) != null) {
        dstExif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF,
                srcExif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF));
    }
    if (srcExif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH) != null) {
        dstExif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH,
                srcExif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH));
    }
    if (srcExif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH) != null) {
        dstExif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH,
                srcExif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH));
    }
    if (srcExif.getAttribute(ExifInterface.TAG_MAKE) != null) {
        dstExif.setAttribute(ExifInterface.TAG_MAKE, srcExif.getAttribute(ExifInterface.TAG_MAKE));
    }
    if (srcExif.getAttribute(ExifInterface.TAG_MODEL) != null) {
        dstExif.setAttribute(ExifInterface.TAG_MODEL, srcExif.getAttribute(ExifInterface.TAG_MODEL));
    }
    if (srcExif.getAttribute(ExifInterface.TAG_ORIENTATION) != null) {
        dstExif.setAttribute(ExifInterface.TAG_ORIENTATION,
                srcExif.getAttribute(ExifInterface.TAG_ORIENTATION));
    }
    if (srcExif.getAttribute(ExifInterface.TAG_WHITE_BALANCE) != null) {
        dstExif.setAttribute(ExifInterface.TAG_WHITE_BALANCE,
                srcExif.getAttribute(ExifInterface.TAG_WHITE_BALANCE));
    }

    dstExif.saveAttributes();
}

From source file:com.wallerlab.compcellscope.Image_Gallery.java

private void writeJsonFile(File[] files) throws JSONException {

    ExifInterface inter;//from   w  ww.ja v a 2  s  . c  om

    //Can write meta deta to the JSON File
    JSONArray image_files = new JSONArray();
    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        JSONObject image = new JSONObject();
        String one = file.getName().toString();

        Log.d(LOG, "Fileyyyyyy: " + file.getPath());
        //Get Information about picture hidden in tags
        try {
            inter = new ExifInterface(file.getPath());
            Log.d(LOG, "Date Taken: " + inter.getAttribute(ExifInterface.TAG_DATETIME));
            Log.d(LOG, "GPSTimeStamp Taken: " + inter.getAttribute(ExifInterface.TAG_GPS_DATESTAMP));
            Log.d(LOG, "Make Taken: " + inter.getAttribute(ExifInterface.TAG_MAKE));
        } catch (IOException e) {
            e.printStackTrace();
        }

        Integer.parseInt(one.substring(one.lastIndexOf("(") + 1, one.lastIndexOf(")")));
        Integer.parseInt(one.substring(one.lastIndexOf("(") + 1, one.lastIndexOf(")")));
        image.put("name", one);
        image.put("focus", Integer.parseInt(one.substring(one.lastIndexOf("(") + 1, one.lastIndexOf(")"))));

        image_files.put(image);
    }

    try {
        FileWriter file = new FileWriter(files[0].getParent().toString() + File.separator + "info.json");
        file.write("test");
        file.flush();
        file.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.almalence.opencam.SavingService.java

protected File saveExifTags(File file, long sessionID, int i, int x, int y, int exif_orientation,
        boolean useGeoTaggingPrefExport, boolean enableExifTagOrientation) {
    addTimestamp(file, exif_orientation);

    // Set tag_model using ExifInterface.
    // If we try set tag_model using ExifDriver, then standard
    // gallery of android (Nexus 4) will crash on this file.
    // Can't figure out why, other Exif tools work fine.
    try {/*from   w w  w.  ja  v a2 s  .c  o  m*/
        ExifInterface ei = new ExifInterface(file.getAbsolutePath());
        String tag_model = getFromSharedMem("exiftag_model" + Long.toString(sessionID));
        String tag_make = getFromSharedMem("exiftag_make" + Long.toString(sessionID));
        if (tag_model == null)
            tag_model = Build.MODEL;
        ei.setAttribute(ExifInterface.TAG_MODEL, tag_model);
        if (tag_make == null)
            tag_make = Build.MANUFACTURER;
        ei.setAttribute(ExifInterface.TAG_MAKE, tag_make);
        ei.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(exif_orientation));
        ei.saveAttributes();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Open ExifDriver.
    ExifDriver exifDriver = ExifDriver.getInstance(file.getAbsolutePath());
    ExifManager exifManager = null;
    if (exifDriver != null) {
        exifManager = new ExifManager(exifDriver, getApplicationContext());
    }

    if (useGeoTaggingPrefExport) {
        Location l = MLocation.getLocation(getApplicationContext());

        if (l != null) {
            double lat = l.getLatitude();
            double lon = l.getLongitude();
            boolean hasLatLon = (lat != 0.0d) || (lon != 0.0d);

            if (hasLatLon) {
                exifManager.setGPSLocation(l.getLatitude(), l.getLongitude(), l.getAltitude());
            }

            String GPSDateString = new SimpleDateFormat("yyyy:MM:dd").format(new Date(l.getTime()));
            if (GPSDateString != null) {
                ValueByteArray value = new ValueByteArray(ExifDriver.FORMAT_ASCII_STRINGS);
                value.setBytes(GPSDateString.getBytes());
                exifDriver.getIfdGps().put(ExifDriver.TAG_GPS_DATE_STAMP, value);
            }
        }
    }

    String tag_exposure_time = getFromSharedMem("exiftag_exposure_time" + Long.toString(sessionID));
    String tag_aperture = getFromSharedMem("exiftag_aperture" + Long.toString(sessionID));
    String tag_flash = getFromSharedMem("exiftag_flash" + Long.toString(sessionID));
    String tag_focal_length = getFromSharedMem("exiftag_focal_lenght" + Long.toString(sessionID));
    String tag_iso = getFromSharedMem("exiftag_iso" + Long.toString(sessionID));
    String tag_white_balance = getFromSharedMem("exiftag_white_balance" + Long.toString(sessionID));
    String tag_spectral_sensitivity = getFromSharedMem(
            "exiftag_spectral_sensitivity" + Long.toString(sessionID));
    String tag_version = getFromSharedMem("exiftag_version" + Long.toString(sessionID));
    String tag_scene = getFromSharedMem("exiftag_scene_capture_type" + Long.toString(sessionID));
    String tag_metering_mode = getFromSharedMem("exiftag_metering_mode" + Long.toString(sessionID));

    if (exifDriver != null) {
        if (tag_exposure_time != null) {
            int[][] ratValue = ExifManager.stringToRational(tag_exposure_time);
            if (ratValue != null) {
                ValueRationals value = new ValueRationals(ExifDriver.FORMAT_UNSIGNED_RATIONAL);
                value.setRationals(ratValue);
                exifDriver.getIfdExif().put(ExifDriver.TAG_EXPOSURE_TIME, value);
            }
        } else { // hack for expo bracketing
            tag_exposure_time = getFromSharedMem(
                    "exiftag_exposure_time" + Integer.toString(i) + Long.toString(sessionID));
            if (tag_exposure_time != null) {
                int[][] ratValue = ExifManager.stringToRational(tag_exposure_time);
                if (ratValue != null) {
                    ValueRationals value = new ValueRationals(ExifDriver.FORMAT_UNSIGNED_RATIONAL);
                    value.setRationals(ratValue);
                    exifDriver.getIfdExif().put(ExifDriver.TAG_EXPOSURE_TIME, value);
                }
            }
        }
        if (tag_aperture != null) {
            int[][] ratValue = ExifManager.stringToRational(tag_aperture);
            if (ratValue != null) {
                ValueRationals value = new ValueRationals(ExifDriver.FORMAT_UNSIGNED_RATIONAL);
                value.setRationals(ratValue);
                exifDriver.getIfdExif().put(ExifDriver.TAG_APERTURE_VALUE, value);
            }
        }
        if (tag_flash != null) {
            ValueNumber value = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_SHORT, Integer.parseInt(tag_flash));
            exifDriver.getIfdExif().put(ExifDriver.TAG_FLASH, value);
        }
        if (tag_focal_length != null) {
            int[][] ratValue = ExifManager.stringToRational(tag_focal_length);
            if (ratValue != null) {
                ValueRationals value = new ValueRationals(ExifDriver.FORMAT_UNSIGNED_RATIONAL);
                value.setRationals(ratValue);
                exifDriver.getIfdExif().put(ExifDriver.TAG_FOCAL_LENGTH, value);
            }
        }
        try {
            if (tag_iso != null) {
                if (tag_iso.indexOf("ISO") > 0) {
                    tag_iso = tag_iso.substring(0, 2);
                }
                ValueNumber value = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_SHORT,
                        Integer.parseInt(tag_iso));
                exifDriver.getIfdExif().put(ExifDriver.TAG_ISO_SPEED_RATINGS, value);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (tag_scene != null) {
            ValueNumber value = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_SHORT, Integer.parseInt(tag_scene));
            exifDriver.getIfdExif().put(ExifDriver.TAG_SCENE_CAPTURE_TYPE, value);
        } else {
            int sceneMode = CameraController.getSceneMode();

            int sceneModeVal = 0;
            if (sceneMode == CameraParameters.SCENE_MODE_LANDSCAPE) {
                sceneModeVal = 1;
            } else if (sceneMode == CameraParameters.SCENE_MODE_PORTRAIT) {
                sceneModeVal = 2;
            } else if (sceneMode == CameraParameters.SCENE_MODE_NIGHT) {
                sceneModeVal = 3;
            }

            ValueNumber value = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_SHORT, sceneModeVal);
            exifDriver.getIfdExif().put(ExifDriver.TAG_SCENE_CAPTURE_TYPE, value);
        }
        if (tag_white_balance != null) {
            exifDriver.getIfd0().remove(ExifDriver.TAG_LIGHT_SOURCE);

            ValueNumber value = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_SHORT,
                    Integer.parseInt(tag_white_balance));
            exifDriver.getIfdExif().put(ExifDriver.TAG_WHITE_BALANCE, value);
            exifDriver.getIfdExif().put(ExifDriver.TAG_LIGHT_SOURCE, value);
        } else {
            exifDriver.getIfd0().remove(ExifDriver.TAG_LIGHT_SOURCE);

            int whiteBalance = CameraController.getWBMode();
            int whiteBalanceVal = 0;
            int lightSourceVal = 0;
            if (whiteBalance == CameraParameters.WB_MODE_AUTO) {
                whiteBalanceVal = 0;
                lightSourceVal = 0;
            } else {
                whiteBalanceVal = 1;
                lightSourceVal = 0;
            }

            if (whiteBalance == CameraParameters.WB_MODE_DAYLIGHT) {
                lightSourceVal = 1;
            } else if (whiteBalance == CameraParameters.WB_MODE_FLUORESCENT) {
                lightSourceVal = 2;
            } else if (whiteBalance == CameraParameters.WB_MODE_WARM_FLUORESCENT) {
                lightSourceVal = 2;
            } else if (whiteBalance == CameraParameters.WB_MODE_INCANDESCENT) {
                lightSourceVal = 3;
            } else if (whiteBalance == CameraParameters.WB_MODE_TWILIGHT) {
                lightSourceVal = 3;
            } else if (whiteBalance == CameraParameters.WB_MODE_CLOUDY_DAYLIGHT) {
                lightSourceVal = 10;
            } else if (whiteBalance == CameraParameters.WB_MODE_SHADE) {
                lightSourceVal = 11;
            }

            ValueNumber valueWB = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_SHORT, whiteBalanceVal);
            exifDriver.getIfdExif().put(ExifDriver.TAG_WHITE_BALANCE, valueWB);

            ValueNumber valueLS = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_SHORT, lightSourceVal);
            exifDriver.getIfdExif().put(ExifDriver.TAG_LIGHT_SOURCE, valueLS);
        }
        if (tag_spectral_sensitivity != null) {
            ValueByteArray value = new ValueByteArray(ExifDriver.FORMAT_ASCII_STRINGS);
            value.setBytes(tag_spectral_sensitivity.getBytes());
            exifDriver.getIfd0().put(ExifDriver.TAG_SPECTRAL_SENSITIVITY, value);
        }
        if (tag_version != null && !tag_version.equals("48 50 50 48")) {
            ValueByteArray value = new ValueByteArray(ExifDriver.FORMAT_ASCII_STRINGS);
            value.setBytes(tag_version.getBytes());
            exifDriver.getIfd0().put(ExifDriver.TAG_EXIF_VERSION, value);
        } else {
            ValueByteArray value = new ValueByteArray(ExifDriver.FORMAT_ASCII_STRINGS);
            byte[] version = { (byte) 48, (byte) 50, (byte) 50, (byte) 48 };
            value.setBytes(version);
            exifDriver.getIfd0().put(ExifDriver.TAG_EXIF_VERSION, value);
        }
        if (tag_metering_mode != null && !tag_metering_mode.equals("")
                && Integer.parseInt(tag_metering_mode) <= 255) {
            ValueNumber value = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_SHORT,
                    Integer.parseInt(tag_metering_mode));
            exifDriver.getIfdExif().put(ExifDriver.TAG_METERING_MODE, value);
            exifDriver.getIfd0().put(ExifDriver.TAG_METERING_MODE, value);
        } else {
            ValueNumber value = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_SHORT, 0);
            exifDriver.getIfdExif().put(ExifDriver.TAG_METERING_MODE, value);
            exifDriver.getIfd0().put(ExifDriver.TAG_METERING_MODE, value);
        }

        ValueNumber xValue = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_LONG, x);
        exifDriver.getIfdExif().put(ExifDriver.TAG_IMAGE_WIDTH, xValue);

        ValueNumber yValue = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_LONG, y);
        exifDriver.getIfdExif().put(ExifDriver.TAG_IMAGE_HEIGHT, yValue);

        String dateString = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss").format(new Date());
        if (dateString != null) {
            ValueByteArray value = new ValueByteArray(ExifDriver.FORMAT_ASCII_STRINGS);
            // Date string length is 19 bytes. But exif tag
            // specification length is 20 bytes.
            // That's why we add "empty" byte (0x00) in the end.
            byte[] bytes = dateString.getBytes();
            byte[] res = new byte[20];
            for (int ii = 0; ii < bytes.length; ii++) {
                res[ii] = bytes[ii];
            }
            res[19] = 0x00;
            value.setBytes(res);
            exifDriver.getIfd0().put(ExifDriver.TAG_DATETIME, value);
            exifDriver.getIfdExif().put(ExifDriver.TAG_DATETIME_DIGITIZED, value);
            exifDriver.getIfdExif().put(ExifDriver.TAG_DATETIME_ORIGINAL, value);
        }

        // extract mode name
        String tag_modename = getFromSharedMem("mode_name" + Long.toString(sessionID));
        if (tag_modename == null)
            tag_modename = "";
        String softwareString = getResources().getString(R.string.app_name) + ", " + tag_modename;
        ValueByteArray softwareValue = new ValueByteArray(ExifDriver.FORMAT_ASCII_STRINGS);
        softwareValue.setBytes(softwareString.getBytes());
        exifDriver.getIfd0().put(ExifDriver.TAG_SOFTWARE, softwareValue);

        if (enableExifTagOrientation) {
            ValueNumber value = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_SHORT, exif_orientation);
            exifDriver.getIfd0().put(ExifDriver.TAG_ORIENTATION, value);
        } else {
            ValueNumber value = new ValueNumber(ExifDriver.FORMAT_UNSIGNED_SHORT,
                    ExifInterface.ORIENTATION_NORMAL);
            exifDriver.getIfd0().put(ExifDriver.TAG_ORIENTATION, value);
        }

        // Save exif info to new file, and replace old file with new
        // one.
        File modifiedFile = new File(file.getAbsolutePath() + ".tmp");
        exifDriver.save(modifiedFile.getAbsolutePath());
        return modifiedFile;
    }
    return null;
}