image.png
拍照后保存到本地文件称开,借助ExifInterface
保存格式必須是JPEG,否則不支持寫入編輯
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
寫入方法很簡單
try {
//保存照片的經(jīng)緯度信息
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, ConvertUtils.convertToDegree(116.2353515625));
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, ConvertUtils.convertToDegree(39.5379397452));
exif.saveAttributes();
//打印結(jié)果
String latValue = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
String lngValue = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
Log.i(TAG, "onCameraData: " + ConvertUtils.convertToCoordinate(latValue) + "--" + ConvertUtils.convertToCoordinate(lngValue));
} catch (IOException e) {
e.printStackTrace();
}
ConvertUtils 工具類
public class ConvertUtils {
//經(jīng)緯度轉(zhuǎn)度分秒
public static String convertToDegree(double gpsInfo) {
String dms = Location.convert(gpsInfo, Location.FORMAT_SECONDS);
return dms;
}
//度分秒轉(zhuǎn)經(jīng)緯度
public static Double convertToCoordinate(String stringDMS) {
if (stringDMS == null) return null;
String[] split = stringDMS.split(":", 3);
return Double.parseDouble(split[0]) + Double.parseDouble(split[1]) / 60 + Double.parseDouble(split[2]) / 3600;
}
}
搞定秦驯。 最后別忘了文件讀寫權(quán)限