ANDROID - 编写EXIF数据

时间:2015-12-05 05:46:06

标签: java android exif

我正在尝试将EXIF元数据写入使用我的应用程序拍摄的照片。但是,它显示错误说:

  

E / JHEAD:无法打开'/sdcard/Pictures/CameraApp/IMG_20151205_133506.jpg'

我正在尝试使用以下代码编写EXIF元数据:

nextWord.push(string(1, str[i + 1]));

以下是权限:

public void loc2Exif(File file) {
    try {
        ExifInterface ef = new ExifInterface(file.getCanonicalPath());
        Log.i("LOCATION", String.valueOf(latitude) + " " + String.valueOf(longitude));
        ef.setAttribute(ExifInterface.TAG_GPS_LATITUDE, dec2DMS(latitude));
        ef.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,dec2DMS(longitude));
        if (latitude > 0)
            ef.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "N");
        else
            ef.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "S");
        if (longitude>0)
            ef.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "E");
        else
            ef.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "W");
        ef.saveAttributes();
    } catch (IOException e) {}
}
static String  dec2DMS(double coord) {
    coord = coord > 0 ? coord : -coord;  // -105.9876543 -> 105.9876543
    String sOut = Integer.toString((int)coord) + "/1,";   // 105/1,
    coord = (coord % 1) * 60;         // .987654321 * 60 = 59.259258
    sOut = sOut + Integer.toString((int)coord) + "/1,";   // 105/1,59/1,
    coord = (coord % 1) * 60000;             // .259258 * 60000 = 15555
    sOut = sOut + Integer.toString((int)coord) + "/1000";   // 105/1,59/1,15555/1000
    return sOut;
}

什么似乎是问题?

0 个答案:

没有答案
相关问题