Android,androidsdk

來源:互聯網
上載者:User

Android,androidsdk
Exif

Exif是一種影像檔格式,它的資料存放區於JPEG格式是完全相同的,實際上Exif格式就是JPEG格式頭插入了數位照片的資訊,包括拍攝的光圈、快門、平衡白、ISO、焦距、日期時間等各種和拍攝條件以及相機品牌、型號、色彩編碼以及GPS等。

ExifInterface

在Android下,通過ExifInterface類操作圖片的Exif資訊,雖然這個類的名字包含Interface,但它不是一個介面,它是一個類,處於"android.media.ExifInterface"包下,是媒體庫的一部分功能的實現。ExifInterface有一個建構函式,接受一個String類型的資料,此為讀取圖片檔案的地址。

Exif資料在圖片中可以理解為Key-value索引值對的方式儲存,一般通過如下幾個方法操作:

String getAttribute(String tag)//擷取圖片中屬性為tag的字串值。double getAttribute(String tag,double defaultValue)//擷取圖片中屬性為tag的double值。int getAttributeInt(String tag,defaultValue//擷取圖片中屬性為tag的int值。void setAttribute(String tag,String value)//根據輸入參數,設定圖片Exif的值。void saveAttrubutes()//把記憶體中圖片的Exif寫入到圖片中。

以看到,上面大部分方法操作了一個String類型的tag參數,此為Exif的屬性,在ExifInterface中定義了一些字串的靜態常量表示這些tag值,常用如下:

TAG_APERTURE//光圈值。TAG_DATETIME//拍攝時間,取決於裝置設定的時間。TAG_EXPOSURE_TIME//曝光時間。TAG_FLASH//閃光燈。TAG_FOCAL_LENGTH//焦距。TAG_IMAGE_LENGTH//圖片高度。TAG_IMAGE_WIDTH//圖片寬度。TAG_ISO//ISO。TAG_MAKE//裝置品牌。TAG_MODEL//裝置型號,整形表示,在ExifInterface中有常量對應表示。TAG_ORIENTATION//旋轉角度,整形表示,在ExifInterface中有常量對應表示。
擷取Exif
ExifInterface exifInterface = new ExifInterface("/sdcard/a.jpg");String FFNumber = exifInterface.getAttribute(ExifInterface.TAG_APERTURE);String FDateTime = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);String FExposureTime = exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);String FFlash = exifInterface.getAttribute(ExifInterface.TAG_FLASH);String FFocalLength = exifInterface.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);String FImageLength = exifInterface.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);String FImageWidth = exifInterface.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);String FISOSpeedRatings = exifInterface.getAttribute(ExifInterface.TAG_ISO);String FMake = exifInterface.getAttribute(ExifInterface.TAG_MAKE);String FModel = exifInterface.getAttribute(ExifInterface.TAG_MODEL);String FOrientation = exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION);String FWhiteBalance = exifInterface.getAttribute(ExifInterface.TAG_WHITE_BALANCE);
寫入Exif

Exif資訊在圖片中以二進位的形式儲存,每個欄位儲存的資料位元數是固定的,並且tag的數量也是固定,所以我們只能操作圖片Exif資訊中已經存在的tag的值,並且儲存的資料要依照它儲存位元的限制,如果儲存的資料類型錯誤,將會導致儲存的資料可能無法正確的取出,超出位元將被截取。如無法將TAG_ORIENTATION中儲存一個字串的資料,它必須儲存int類型的值,多出來的將被截取。

// tagString strAttr = ExifInterface.TAG_ORIENTATION;// tag-valueString strValue = et_value.getText().toString().trim();// 擷取圖片ExifExifInterface exif = new ExifInterface("/sdcard/a.jpg");// 儲存指定tag的值exif.setAttribute(strAttr,strValue);// 把Exif資訊寫入靶心圖表片exif.saveAttributes();
我是天王蓋地虎的分割線

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.