日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

android android 修改 jpg exif 属性,Android开发之使用ExifInterface获取拍照后的图片属性...

發(fā)布時(shí)間:2023/12/10 Android 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android android 修改 jpg exif 属性,Android开发之使用ExifInterface获取拍照后的图片属性... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

本文實(shí)例講述了Android開發(fā)之使用ExifInterface獲取拍照后的圖片屬性。分享給大家供大家參考,具體如下:

ExifInterface exif = new ExifInterface(file.getPath());

String widthStr = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);

String heightStr = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);

......

/*

* Copyright (C) 2007 The Android Open Source Project

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

package android.media;

import java.io.IOException;

import java.text.ParsePosition;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.HashMap;

import java.util.Map;

import java.util.TimeZone;

/**

* This is a class for reading and writing Exif tags in a JPEG file.

*/

public class ExifInterface {

// The Exif tag names

/** Type is int. */

public static final String TAG_ORIENTATION = "Orientation";

/** Type is String. */

public static final String TAG_DATETIME = "DateTime";

/** Type is String. */

public static final String TAG_MAKE = "Make";

/** Type is String. */

public static final String TAG_MODEL = "Model";

/** Type is int. */

public static final String TAG_FLASH = "Flash";

/** Type is int. */

public static final String TAG_IMAGE_WIDTH = "ImageWidth";

/** Type is int. */

public static final String TAG_IMAGE_LENGTH = "ImageLength";

/** String. Format is "num1/denom1,num2/denom2,num3/denom3". */

public static final String TAG_GPS_LATITUDE = "GPSLatitude";

/** String. Format is "num1/denom1,num2/denom2,num3/denom3". */

public static final String TAG_GPS_LONGITUDE = "GPSLongitude";

/** Type is String. */

public static final String TAG_GPS_LATITUDE_REF = "GPSLatitudeRef";

/** Type is String. */

public static final String TAG_GPS_LONGITUDE_REF = "GPSLongitudeRef";

/** Type is String. */

public static final String TAG_GPS_TIMESTAMP = "GPSTimeStamp";

/** Type is String. */

public static final String TAG_GPS_DATESTAMP = "GPSDateStamp";

/** Type is int. */

public static final String TAG_WHITE_BALANCE = "WhiteBalance";

/** Type is rational. */

public static final String TAG_FOCAL_LENGTH = "FocalLength";

/** Type is String. Name of GPS processing method used for location finding. */

public static final String TAG_GPS_PROCESSING_METHOD = "GPSProcessingMethod";

// Constants used for the Orientation Exif tag.

public static final int ORIENTATION_UNDEFINED = 0;

public static final int ORIENTATION_NORMAL = 1;

public static final int ORIENTATION_FLIP_HORIZONTAL = 2; // left right reversed mirror

public static final int ORIENTATION_ROTATE_180 = 3;

public static final int ORIENTATION_FLIP_VERTICAL = 4; // upside down mirror

public static final int ORIENTATION_TRANSPOSE = 5; // flipped about top-left bottom-right axis

public static final int ORIENTATION_ROTATE_90 = 6; // rotate 90 cw to right it

public static final int ORIENTATION_TRANSVERSE = 7; // flipped about top-right bottom-left axis

public static final int ORIENTATION_ROTATE_270 = 8; // rotate 270 to right it

// Constants used for white balance

public static final int WHITEBALANCE_AUTO = 0;

public static final int WHITEBALANCE_MANUAL = 1;

private static SimpleDateFormat sFormatter;

static {

System.loadLibrary("exif");

sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");

sFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));

}

private String mFilename;

private HashMap mAttributes;

private boolean mHasThumbnail;

// Because the underlying implementation (jhead) uses static variables,

// there can only be one user at a time for the native functions (and

// they cannot keep state in the native code across function calls). We

// use sLock to serialize the accesses.

private static Object sLock = new Object();

/**

* Reads Exif tags from the specified JPEG file.

*/

public ExifInterface(String filename) throws IOException {

mFilename = filename;

loadAttributes();

}

/**

* Returns the value of the specified tag or {@code null} if there

* is no such tag in the JPEG file.

*

* @param tag the name of the tag.

*/

public String getAttribute(String tag) {

return mAttributes.get(tag);

}

/**

* Returns the integer value of the specified tag. If there is no such tag

* in the JPEG file or the value cannot be parsed as integer, return

* defaultValue.

*

* @param tag the name of the tag.

* @param defaultValue the value to return if the tag is not available.

*/

public int getAttributeInt(String tag, int defaultValue) {

String value = mAttributes.get(tag);

if (value == null) return defaultValue;

try {

return Integer.valueOf(value);

} catch (NumberFormatException ex) {

return defaultValue;

}

}

/**

* Returns the double value of the specified rational tag. If there is no

* such tag in the JPEG file or the value cannot be parsed as double, return

* defaultValue.

*

* @param tag the name of the tag.

* @param defaultValue the value to return if the tag is not available.

*/

public double getAttributeDouble(String tag, double defaultValue) {

String value = mAttributes.get(tag);

if (value == null) return defaultValue;

try {

int index = value.indexOf("/");

if (index == -1) return defaultValue;

double denom = Double.parseDouble(value.substring(index + 1));

if (denom == 0) return defaultValue;

double num = Double.parseDouble(value.substring(0, index));

return num / denom;

} catch (NumberFormatException ex) {

return defaultValue;

}

}

/**

* Set the value of the specified tag.

*

* @param tag the name of the tag.

* @param value the value of the tag.

*/

public void setAttribute(String tag, String value) {

mAttributes.put(tag, value);

}

/**

* Initialize mAttributes with the attributes from the file mFilename.

*

* mAttributes is a HashMap which stores the Exif attributes of the file.

* The key is the standard tag name and the value is the tag's value: e.g.

* Model -> Nikon. Numeric values are stored as strings.

*

* This function also initialize mHasThumbnail to indicate whether the

* file has a thumbnail inside.

*/

private void loadAttributes() throws IOException {

// format of string passed from native C code:

// "attrCnt attr1=valueLen value1attr2=value2Len value2..."

// example:

// "4 attrPtr ImageLength=4 1024Model=6 FooImageWidth=4 1280Make=3 FOO"

mAttributes = new HashMap();

String attrStr;

synchronized (sLock) {

attrStr = getAttributesNative(mFilename);

}

// get count

int ptr = attrStr.indexOf(' ');

int count = Integer.parseInt(attrStr.substring(0, ptr));

// skip past the space between item count and the rest of the attributes

++ptr;

for (int i = 0; i < count; i++) {

// extract the attribute name

int equalPos = attrStr.indexOf('=', ptr);

String attrName = attrStr.substring(ptr, equalPos);

ptr = equalPos + 1; // skip past =

// extract the attribute value length

int lenPos = attrStr.indexOf(' ', ptr);

int attrLen = Integer.parseInt(attrStr.substring(ptr, lenPos));

ptr = lenPos + 1; // skip pas the space

// extract the attribute value

String attrValue = attrStr.substring(ptr, ptr + attrLen);

ptr += attrLen;

if (attrName.equals("hasThumbnail")) {

mHasThumbnail = attrValue.equalsIgnoreCase("true");

} else {

mAttributes.put(attrName, attrValue);

}

}

}

/**

* Save the tag data into the JPEG file. This is expensive because it involves

* copying all the JPG data from one file to another and deleting the old file

* and renaming the other. It's best to use {@link #setAttribute(String,String)}

* to set all attributes to write and make a single call rather than multiple

* calls for each attribute.

*/

public void saveAttributes() throws IOException {

// format of string passed to native C code:

// "attrCnt attr1=valueLen value1attr2=value2Len value2..."

// example:

// "4 attrPtr ImageLength=4 1024Model=6 FooImageWidth=4 1280Make=3 FOO"

StringBuilder sb = new StringBuilder();

int size = mAttributes.size();

if (mAttributes.containsKey("hasThumbnail")) {

--size;

}

sb.append(size + " ");

for (Map.Entry iter : mAttributes.entrySet()) {

String key = iter.getKey();

if (key.equals("hasThumbnail")) {

// this is a fake attribute not saved as an exif tag

continue;

}

String val = iter.getValue();

sb.append(key + "=");

sb.append(val.length() + " ");

sb.append(val);

}

String s = sb.toString();

synchronized (sLock) {

saveAttributesNative(mFilename, s);

commitChangesNative(mFilename);

}

}

/**

* Returns true if the JPEG file has a thumbnail.

*/

public boolean hasThumbnail() {

return mHasThumbnail;

}

/**

* Returns the thumbnail inside the JPEG file, or {@code null} if there is no thumbnail.

* The returned data is in JPEG format and can be decoded using

* {@link android.graphics.BitmapFactory#decodeByteArray(byte[],int,int)}

*/

public byte[] getThumbnail() {

synchronized (sLock) {

return getThumbnailNative(mFilename);

}

}

/**

* Stores the latitude and longitude value in a float array. The first element is

* the latitude, and the second element is the longitude. Returns false if the

* Exif tags are not available.

*/

public boolean getLatLong(float output[]) {

String latValue = mAttributes.get(ExifInterface.TAG_GPS_LATITUDE);

String latRef = mAttributes.get(ExifInterface.TAG_GPS_LATITUDE_REF);

String lngValue = mAttributes.get(ExifInterface.TAG_GPS_LONGITUDE);

String lngRef = mAttributes.get(ExifInterface.TAG_GPS_LONGITUDE_REF);

if (latValue != null && latRef != null && lngValue != null && lngRef != null) {

output[0] = convertRationalLatLonToFloat(latValue, latRef);

output[1] = convertRationalLatLonToFloat(lngValue, lngRef);

return true;

} else {

return false;

}

}

/**

* Returns number of milliseconds since Jan. 1, 1970, midnight.

* Returns -1 if the date time information if not available.

* @hide

*/

public long getDateTime() {

String dateTimeString = mAttributes.get(TAG_DATETIME);

if (dateTimeString == null) return -1;

ParsePosition pos = new ParsePosition(0);

try {

Date datetime = sFormatter.parse(dateTimeString, pos);

if (datetime == null) return -1;

return datetime.getTime();

} catch (IllegalArgumentException ex) {

return -1;

}

}

/**

* Returns number of milliseconds since Jan. 1, 1970, midnight UTC.

* Returns -1 if the date time information if not available.

* @hide

*/

public long getGpsDateTime() {

String date = mAttributes.get(TAG_GPS_DATESTAMP);

String time = mAttributes.get(TAG_GPS_TIMESTAMP);

if (date == null || time == null) return -1;

String dateTimeString = date + ' ' + time;

if (dateTimeString == null) return -1;

ParsePosition pos = new ParsePosition(0);

try {

Date datetime = sFormatter.parse(dateTimeString, pos);

if (datetime == null) return -1;

return datetime.getTime();

} catch (IllegalArgumentException ex) {

return -1;

}

}

private static float convertRationalLatLonToFloat(

String rationalString, String ref) {

try {

String [] parts = rationalString.split(",");

String [] pair;

pair = parts[0].split("/");

int degrees = (int) (Float.parseFloat(pair[0].trim())

/ Float.parseFloat(pair[1].trim()));

pair = parts[1].split("/");

int minutes = (int) ((Float.parseFloat(pair[0].trim())

/ Float.parseFloat(pair[1].trim())));

pair = parts[2].split("/");

float seconds = Float.parseFloat(pair[0].trim())

/ Float.parseFloat(pair[1].trim());

float result = degrees + (minutes / 60F) + (seconds / (60F * 60F));

if ((ref.equals("S") || ref.equals("W"))) {

return -result;

}

return result;

} catch (RuntimeException ex) {

// if for whatever reason we can't parse the lat long then return

// null

return 0f;

}

}

private native boolean appendThumbnailNative(String fileName,

String thumbnailFileName);

private native void saveAttributesNative(String fileName,

String compressedAttributes);

private native String getAttributesNative(String fileName);

private native void commitChangesNative(String fileName);

private native byte[] getThumbnailNative(String fileName);

}

更多關(guān)于Android開發(fā)相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》及《Android圖形與圖像處理技巧總結(jié)》

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

總結(jié)

以上是生活随笔為你收集整理的android android 修改 jpg exif 属性,Android开发之使用ExifInterface获取拍照后的图片属性...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 不卡的日韩av | 美女在线不卡 | 男女啪啪十八 | 美女一区二区三区视频 | 国产久操视频 | aa成人 | 操操操爽爽爽 | 国产精品久久久久久亚洲毛片 | 久久久久国产视频 | 精品日韩一区二区三区四区 | 艳母在线视频 | av资源在线| 亚洲高清免费观看 | 日韩第一页 | 91精品国产电影 | 91免费在线看 | av基地| 少妇太紧太爽又黄又硬又爽 | 欧美播放器 | 成人国产精品久久久 | 日韩一区二区视频在线播放 | 国产无遮挡a片又黄又爽 | 99极品视频 | 天天操操操| 成人免费在线观看 | 国产 日韩 欧美在线 | 国产一区二区视频在线播放 | 亚色在线视频 | 精品在线免费观看视频 | 国产在线激情 | 一级片www | 亚洲最大av网站 | 91视频免费在线 | 日韩在线观看第一页 | 亚洲视频在线观看一区 | 成人免费观看在线视频 | aa在线| 天天爱夜夜爽 | 在线免费看污网站 | 国产盗摄一区二区三区在线 | 国产精品九九热 | 亚洲精品无码一区二区 | 中文字幕+乱码+中文 | 欧美高清日韩 | 鲁丝一区二区三区 | 日本国产精品一区 | 探花国产 | 欧美一级夜夜爽 | 90岁老太婆乱淫 | 清纯唯美第一页 | 精品国产一区在线 | 日本伊人网 | 精品国产一二三区 | 成人羞羞国产免费动态 | 九九热最新视频 | 亚洲A∨无码国产精品 | 女人被狂躁c到高潮喷水电影 | 农村偷人一级超爽毛片 | 色综合久久88色综合天天免费 | 一个人看的www视频在线观看 | 三级亚洲欧美 | 韩国一区二区在线播放 | 老熟妇一区二区三区 | 一级片在线| 日本伦理一区二区三区 | 国产精品你懂的 | 久久免费看视频 | 日韩精品免费一区二区三区 | 国产精品福利导航 | 国产一区精品久久 | 动漫美女视频 | 日批视频免费观看 | 男生和女生差差的视频 | 梦梦电影免费高清在线观看 | 六月激情网 | 好av在线| 国产精品一区二区久久国产 | 影音先锋日韩资源 | 美国av毛片 | 丝袜熟女一区二区三区 | av在线导航 | 欧美怡红院视频一区二区三区 | 欧美三级一区二区三区 | 黑人操亚洲美女 | 日韩一区二区三区三四区视频在线观看 | 成人在线小视频 | av有声小说一区二区三区 | 亚洲精品在线免费 | 天堂国产在线 | 亚洲系列| 亚洲色图首页 | 男人天堂网av | 黄色精品免费 | 久久激情五月 | 午夜国产视频 | 777午夜| 免费看黄色a级片 | china国模大尺度pics | 成人精品在线 |