最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android實現(xiàn)將位置信息寫入JPEG圖片文件

 更新時間:2017年03月10日 10:34:47   投稿:jingxian  
下面小編就為大家?guī)硪黄猘ndroid實現(xiàn)將位置信息寫入JPEG圖片文件。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

通過ExifInterface可以將拍照時的一些屬性信息寫入圖片文件里,其中包括經(jīng)緯度信息。本文介紹一種將經(jīng)緯度坐標寫入JPEG圖片文件的方法!

核心代碼

/**
* 浮點型經(jīng)緯度值轉(zhuǎn)成度分秒格式
* 
* @param coord
* @return
*/
	public String decimalToDMS(double coord) {
	String output, degrees, minutes, seconds;

// gets the modulus the coordinate divided by one (MOD1).
// in other words gets all the numbers after the decimal point.
// e.g. mod := -79.982195 % 1 == 0.982195
//
// next get the integer part of the coord. On other words the whole
// number part.
// e.g. intPart := -79

	double mod = coord % 1;
	int intPart = (int) coord;

// set degrees to the value of intPart
// e.g. degrees := "-79"

	degrees = String.valueOf(intPart);

// next times the MOD1 of degrees by 60 so we can find the integer part
// for minutes.
// get the MOD1 of the new coord to find the numbers after the decimal
// point.
// e.g. coord := 0.982195 * 60 == 58.9317
// mod := 58.9317 % 1 == 0.9317
//
// next get the value of the integer part of the coord.
// e.g. intPart := 58

	coord = mod * 60;
	mod = coord % 1;
	intPart = (int) coord;
	if (intPart < 0) {
		// Convert number to positive if it's negative.
		intPart *= -1;
}

// set minutes to the value of intPart.
// e.g. minutes = "58"
	minutes = String.valueOf(intPart);

// do the same again for minutes
// e.g. coord := 0.9317 * 60 == 55.902
// e.g. intPart := 55
	coord = mod * 60;
	intPart = (int) coord;
	if (intPart < 0) {
		// Convert number to positive if it's negative.
		intPart *= -1;
	}

// set seconds to the value of intPart.
// e.g. seconds = "55"
	seconds = String.valueOf(intPart);

// I used this format for android but you can change it
// to return in whatever format you like
// e.g. output = "-79/1,58/1,56/1"
	output = degrees + "/1," + minutes + "/1," + seconds + "/1";

// Standard output of D°M′S″
// output = degrees + "°" + minutes + "'" + seconds + "\"";

	return output;
	}

/**
* 將經(jīng)緯度信息寫入JPEG圖片文件里
* 
* @param picPath
*      JPEG圖片文件路徑
* @param dLat
*      緯度
* @param dLon
*      經(jīng)度
*/
	public void writeLatLonIntoJpeg(String picPath, double dLat, double dLon) {
	File file = new File(picPath);
	if (file.exists()) {
	try {
	ExifInterface exif = new ExifInterface(picPath);
	String tagLat = exif
	.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
	String tagLon = exif
	.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
	if (tagLat == null && tagLon == null) // 無經(jīng)緯度信息
{
	exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE,
	decimalToDMS(dLat));
	exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF,
	dLat > 0 ? "N" : "S"); // 區(qū)分南北半球
	exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,
	decimalToDMS(dLon));
	exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF,
	dLon > 0 ? "E" : "W"); // 區(qū)分東經(jīng)西經(jīng)

	exif.saveAttributes();
}
	} catch (Exception e) {

	}
}
	}

測試代碼

String strImgPath = getImageCachePath() + File.separator + "1.jpg";

ExifInterface eif = new ExifInterface(strImgPath);
String lat = eif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
String latRef = eif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
String lon = eif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
String lonRef = eif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);

System.out.println("Latitude Ref - " + latRef);
System.out.println("Latitude - " + lat);
System.out.println("Longitude Ref - " + lonRef);
System.out.println("Longitude - " + lon);

if (lat == null && lon == null) // 沒有位置信息才寫入
{
 writeLatLonIntoJpeg(strImgPath, 39.23456, 116.123456);
}

第一次運行結(jié)果

05-22 17:36:24.566: I/System.out(17966): Latitude Ref - null
05-22 17:36:24.566: I/System.out(17966): Latitude - null
05-22 17:36:24.566: I/System.out(17966): Longitude Ref - null
05-22 17:36:24.566: I/System.out(17966): Longitude - null

原始圖片沒有位置信息,通過調(diào)用writeLatLonIntoJpeg(strImgPath, 39.23456, 116.123456)來模擬寫入一個位置。

第二次運行結(jié)果

05-22 17:37:11.446: I/System.out(17966): Latitude Ref - N
05-22 17:37:11.446: I/System.out(17966): Latitude - 39/1,14/1,4/1
05-22 17:37:11.446: I/System.out(17966): Longitude Ref - E
05-22 17:37:11.446: I/System.out(17966): Longitude - 116/1,7/1,24/1

以上這篇android實現(xiàn)將位置信息寫入JPEG圖片文件就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android EditText設(shè)置邊框的操作方法

    Android EditText設(shè)置邊框的操作方法

    這篇文章主要介紹了Android EditText設(shè)置邊框,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-12-12
  • 詳解Flutter掃碼識別二維碼內(nèi)容

    詳解Flutter掃碼識別二維碼內(nèi)容

    這篇文章主要介紹了Flutter掃碼識別二維碼內(nèi)容的相關(guān)知識,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-11-11
  • Android劉海屏、水滴屏全面屏適配小結(jié)

    Android劉海屏、水滴屏全面屏適配小結(jié)

    這篇文章主要介紹了Android劉海屏、水滴屏全面屏適配小結(jié),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-06-06
  • Android線程實現(xiàn)圖片輪播

    Android線程實現(xiàn)圖片輪播

    這篇文章主要介紹了Android線程實現(xiàn)圖片輪播,初始化3秒更換一次圖片背景,輪換播放,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Flutter中嵌入Android 原生TextView實例教程

    Flutter中嵌入Android 原生TextView實例教程

    這篇文章主要給大家介紹了關(guān)于Flutter中嵌入Android 原生TextView的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-09-09
  • Android進階教程之ViewGroup自定義布局

    Android進階教程之ViewGroup自定義布局

    這篇文章主要給大家介紹了關(guān)于Android進階教程之ViewGroup自定義布局的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-06-06
  • Android實現(xiàn)文件下載進度顯示功能

    Android實現(xiàn)文件下載進度顯示功能

    這篇文章主要為大家詳細介紹了Android實現(xiàn)文件下載進度顯示功能,檢測Android文件下載進度,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-02-02
  • Android?adb?shell?dumpsys?audio?信息查看分析詳解

    Android?adb?shell?dumpsys?audio?信息查看分析詳解

    文章詳細介紹了如何使用dumpsysaudio命令查看和分析Android設(shè)備的音頻信息,包括音頻流狀態(tài)、音量、外設(shè)連接情況等,文章還提供了示例日志分析和源碼鏈接,幫助開發(fā)者更好地理解和調(diào)試Android音頻系統(tǒng)
    2024-11-11
  • Android點擊事件之多點觸摸與手勢識別的實現(xiàn)

    Android點擊事件之多點觸摸與手勢識別的實現(xiàn)

    這篇文章主要介紹了Android點擊事件之多點觸摸與手勢識別的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-05-05
  • Android 如何保證service在后臺不被kill

    Android 如何保證service在后臺不被kill

    本文主要介紹了Android 如何保證service在后臺不被kill的方法。具有很好的參考價值,下面跟著小編一起來看下吧
    2017-02-02

最新評論

沁源县| 哈巴河县| 赣州市| 鲁甸县| 南靖县| 辽源市| 阳高县| 尖扎县| 葫芦岛市| 万全县| 吉木萨尔县| 阳山县| 南乐县| 青浦区| 芮城县| 固原市| 墨竹工卡县| 新晃| 石门县| 鞍山市| 渝北区| 武平县| 拜城县| 颍上县| 潞西市| 多伦县| 东安县| 花莲县| 莲花县| 淳化县| 左权县| 麻城市| 禄丰县| 营口市| 平舆县| 西昌市| 阿克陶县| 黄浦区| 体育| 青冈县| 肥东县|