With the release of the href="https://developer.android.com/topic/libraries/support-library/revisions.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#rev25-1-0">25.1.0 Support Library, there's a new entry in the family: the ExifInterface Support Library. With significant improvements introduced in Android 7.1 to the framework's href="https://developer.android.com/reference/android/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog">ExifInterface
, it only made sense to make those available to all API 9+ devices via the Support Library's ExifInterface
.
The basics are still the same: the ability to read and write href="https://en.wikipedia.org/wiki/Exif?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog">Exif tags embedded within image files: now with 140 different attributes (almost 100 of them new to Android 7.1/this Support Library!) including information about the camera itself, the camera settings, orientation, and GPS coordinates.
Camera Apps: Writing Exif Attributes
For Camera apps, the writing is probably the most important - writing attributes is still limited to JPEG image files. Now, normally you wouldn't need to use this during the actual camera capturing itself - you'd instead be calling the Camera2 API href="https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Builder.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#set(android.hardware.camera2.CaptureRequest.Key%3CT%3D,%20T)">CaptureRequest.Builder.set()
with href="https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#JPEG_ORIENTATION">JPEG_ORIENTATION
, href="https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#JPEG_GPS_LOCATION">JPEG_GPS_LOCATION
or the equivalents in the Camera1 href="https://developer.android.com/reference/android/hardware/Camera.Parameters.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog">Camera.Parameters
. However, using ExifInterface
allows you to make changes to the file after the fact (say, removing the location information on the user's request).
Reading Exif Attributes
For the rest of us though, reading those attributes is going to be our bread-and-butter; this is where we see the biggest improvements.
Firstly, you can read Exif data from JPEG and raw images (specifically, DNG, CR2, NEF, NRW, ARW, RW2, ORF, PEF, SRW and RAF files). Under the hood, this was a major restructuring, removing all native dependencies and building an extensive test suite to ensure that everything actually works.
For apps that receive images from other apps with a content://
URI (such as those sent by apps that href="https://developer.android.com/about/versions/nougat/android-7.0-changes.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#sharing-files">target API 24 or higher), ExifInterface
now works directly off of an InputStream
; this allows you to easily extract Exif information directly out of content://
URIs you receive without having to create a temporary file.
InputStream in;
try {
in = getContentResolver().openInputStream(uri);
ExifInterface exifInterface = new ExifInterface(in);
// Now you can extract any Exif tag you want
// Assuming the image is a JPEG or supported raw format
} catch (IOException e) {
// Handle any errors
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ignored) {}
}
}
Note: ExifInterface
will not work with remote InputStream
s, such as those returned from a href="https://developer.android.com/reference/java/net/HttpURLConnection.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog">HttpURLConnection
. It is strongly recommended to only use them with content://
or file://
URIs.
For most attributes, you'd simply use the href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#getAttributeInt(java.lang.String,%20int)">getAttributeInt()
, href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#getAttributeDouble(java.lang.String,%20double)">getAttributeDouble()
, or href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#getAttribute(java.lang.String)">getAttribute()
(for Strings) methods as appropriate.
One of the most important attributes when it comes to displaying images is the image orientation, stored in the aptly-named href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#TAG_ORIENTATION">TAG_ORIENTATION
, which returns one of the ORIENTATION_
constants. To convert this to a rotation angle, you can post-process the value.
int orientation = exifInterface.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotation = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotation = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotation = 270;
break;
}
There are some helper methods to extract values from specific Exif tags. For location data, the href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#getLatLong(float[])">getLatLong()
method gives you the latitude and longitude as floats and href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#getAltitude(double)">getAltitude()
will give you the altitude in meters. Some images also embed a small thumbnail. You can check for its existence with href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#hasThumbnail()">hasThumbnail()
and then extract the byte[]
representation of the thumbnail with href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#getThumbnail()">getThumbnail()
- perfect to pass to href="https://developer.android.com/reference/android/graphics/BitmapFactory.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#decodeByteArray(byte[],%20int,%20int)">BitmapFactory.decodeByteArray()
.
Working with Exif: Everything is optional
One thing that is important to understand with Exif data is that there are no required tags: each and every tag is optional - some services even specifically strip Exif data. Therefore throughout your code, you should always handle cases where there is no Exif data, either due to no data for a specific attribute or an image format that doesn't support Exif data at all (say, the ubiquitous PNGs or WebP images).
Add the ExifInterface Support Library to your project with the following dependency:
class="prettyprint">compile "com.android.support:exifinterface:25.1.0"But when an Exif attribute is exactly what you need to prevent a mis-rotated image in your app, the ExifInterface Support Library is just what you need to #BuildBetterApps
With the release of the href="https://developer.android.com/topic/libraries/support-library/revisions.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#rev25-1-0">25.1.0 Support Library, there's a new entry in the family: the ExifInterface Support Library. With significant improvements introduced in Android 7.1 to the framework's href="https://developer.android.com/reference/android/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog">ExifInterface
, it only made sense to make those available to all API 9+ devices via the Support Library's ExifInterface
.
The basics are still the same: the ability to read and write href="https://en.wikipedia.org/wiki/Exif?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog">Exif tags embedded within image files: now with 140 different attributes (almost 100 of them new to Android 7.1/this Support Library!) including information about the camera itself, the camera settings, orientation, and GPS coordinates.
Camera Apps: Writing Exif Attributes
For Camera apps, the writing is probably the most important - writing attributes is still limited to JPEG image files. Now, normally you wouldn't need to use this during the actual camera capturing itself - you'd instead be calling the Camera2 API href="https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Builder.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#set(android.hardware.camera2.CaptureRequest.Key%3CT%3D,%20T)">CaptureRequest.Builder.set()
with href="https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#JPEG_ORIENTATION">JPEG_ORIENTATION
, href="https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#JPEG_GPS_LOCATION">JPEG_GPS_LOCATION
or the equivalents in the Camera1 href="https://developer.android.com/reference/android/hardware/Camera.Parameters.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog">Camera.Parameters
. However, using ExifInterface
allows you to make changes to the file after the fact (say, removing the location information on the user's request).
Reading Exif Attributes
For the rest of us though, reading those attributes is going to be our bread-and-butter; this is where we see the biggest improvements.
Firstly, you can read Exif data from JPEG and raw images (specifically, DNG, CR2, NEF, NRW, ARW, RW2, ORF, PEF, SRW and RAF files). Under the hood, this was a major restructuring, removing all native dependencies and building an extensive test suite to ensure that everything actually works.
For apps that receive images from other apps with a content://
URI (such as those sent by apps that href="https://developer.android.com/about/versions/nougat/android-7.0-changes.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#sharing-files">target API 24 or higher), ExifInterface
now works directly off of an InputStream
; this allows you to easily extract Exif information directly out of content://
URIs you receive without having to create a temporary file.
InputStream in;
try {
in = getContentResolver().openInputStream(uri);
ExifInterface exifInterface = new ExifInterface(in);
// Now you can extract any Exif tag you want
// Assuming the image is a JPEG or supported raw format
} catch (IOException e) {
// Handle any errors
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ignored) {}
}
}
Note: ExifInterface
will not work with remote InputStream
s, such as those returned from a href="https://developer.android.com/reference/java/net/HttpURLConnection.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog">HttpURLConnection
. It is strongly recommended to only use them with content://
or file://
URIs.
For most attributes, you'd simply use the href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#getAttributeInt(java.lang.String,%20int)">getAttributeInt()
, href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#getAttributeDouble(java.lang.String,%20double)">getAttributeDouble()
, or href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#getAttribute(java.lang.String)">getAttribute()
(for Strings) methods as appropriate.
One of the most important attributes when it comes to displaying images is the image orientation, stored in the aptly-named href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#TAG_ORIENTATION">TAG_ORIENTATION
, which returns one of the ORIENTATION_
constants. To convert this to a rotation angle, you can post-process the value.
int orientation = exifInterface.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotation = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotation = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotation = 270;
break;
}
There are some helper methods to extract values from specific Exif tags. For location data, the href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#getLatLong(float[])">getLatLong()
method gives you the latitude and longitude as floats and href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#getAltitude(double)">getAltitude()
will give you the altitude in meters. Some images also embed a small thumbnail. You can check for its existence with href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#hasThumbnail()">hasThumbnail()
and then extract the byte[]
representation of the thumbnail with href="https://developer.android.com/reference/android/support/media/ExifInterface.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#getThumbnail()">getThumbnail()
- perfect to pass to href="https://developer.android.com/reference/android/graphics/BitmapFactory.html?utm_campaign=android_launch_exifsupportlibrary_122116&utm_source=anddev&utm_medium=blog#decodeByteArray(byte[],%20int,%20int)">BitmapFactory.decodeByteArray()
.
Working with Exif: Everything is optional
One thing that is important to understand with Exif data is that there are no required tags: each and every tag is optional - some services even specifically strip Exif data. Therefore throughout your code, you should always handle cases where there is no Exif data, either due to no data for a specific attribute or an image format that doesn't support Exif data at all (say, the ubiquitous PNGs or WebP images).
Add the ExifInterface Support Library to your project with the following dependency:
class="prettyprint">compile "com.android.support:exifinterface:25.1.0"But when an Exif attribute is exactly what you need to prevent a mis-rotated image in your app, the ExifInterface Support Library is just what you need to #BuildBetterApps
download Introducing the ExifInterface Support Library android terbaru, apk android terbaru Introducing the ExifInterface Support Library android asus, Introducing the ExifInterface Support Library android advance, Introducing the ExifInterface Support Library android apk, Introducing the ExifInterface Support Library android app, Introducing the ExifInterface Support Library android games, Introducing the ExifInterface Support Library android programming, Introducing the ExifInterface Support Library aplikasi edit foto,Introducing the ExifInterface Support Library aplikasi facebook, Introducing the ExifInterface Support Library aplikasi bbm
Introducing the ExifInterface Support Library
,Introducing the ExifInterface Support Library aplikasi edit video
aplikasi vidmate Introducing the ExifInterface Support Library aplikasi wa, aplikasi play store Introducing the ExifInterface Support Library Download, Download Introducing the ExifInterface Support Library indonesia aplikasi download lagu, aplikasi pembobol wifi Introducing the ExifInterface Support Library Google Drive, download aplikasi instagram Introducing the ExifInterface Support Library 3gp,Introducing the ExifInterface Support Library mp4,Introducing the ExifInterface Support Library mkv, Introducing the ExifInterface Support Library google drive, Introducing the ExifInterface Support Library 480p,Introducing the ExifInterface Support Library 720p, aplikasi android terbaik Introducing the ExifInterface Support Library,download aplikasi anti virus, aplikasi bigo live, download template web gratis, download template gratis, template website php, template website responsive, template blogspot, download template html, download template website dinamis gratis, download template premium, download template mirip atau clone, Download Professional XML Blogspot Templates, Free Blogger Templates, download blogger template responsive, Introducing the ExifInterface Support Library download template blogger seo, download template blog xml, download template blog gratis terbaru, download template blog simple, download template blogger keren, cara mengganti template blog, download template fast loading seo friendly, Cara posting artikel, Cara memasang widget, Memahami menu-menu di blogger, Cara mengganti atau memasang template, Cara membuat halaman statis, Cara memasang favicon, Cara mengganti judul blog dengan logo, 10 Tutorial blogger lainnya, Cara Menghasilkan Uang dari Blog , Panduan Lengkap, Rahasia Cara Daftar Google AdSense Agar Mudah Diterima, SEO, BLOG, DAN INTERNET MARKETING, Tutorial Belajar SEO dan Blogging juga Internet Marketing Terpadu Yang Mudah Untuk Anda Pelajari, BELAJAR SEO, cara tutorial Membuat Website Wordpress, Cara Cepat Mendapatkan Backlink Untuk Menaikkan Ranking, Download Free Template Blog SEO Friendly Responsive Design Mudah Diedit, Cara membuat blog di blogger com, Cara Melakukan Optimasi SEO Onpage Google Dengan Benar, Berbagai Cara Cari Uang Di Internet Yang Perlu Anda Tahu, CARA MUDAH MEMBUAT THUMBNAIL POST WARNA WARNI SESUAI LABEL POST, CARA MEMBUAT BLOG SEO 100 DI CHKME COM, 5 TEMPLATES BLOGGER SEO RESPONSIVE KEREN TERBAIK 2017 GRATIS, CARA AGAR ARTIKEL ATAU POSTINGAN CEPAT TERINDEX GOOGLE, LANGKAH LANGKAH OPTIMASI ONPAGE PADA BLOG, CARA DAPAT UANG DARI BERBAGAI BISNIS ONLINE, UPLOAD VIDEO DI FACEBOOK BISA DAPAT UANG, CARA MEMBUAT WIDGET TWITTER DI BLOGGER BLOGSPOT, CARA MEMBUAT BREADCRUMBS SEO FRIENDLY DENGAN FONT AWESOME, MEMBUAT TOMBOL BACK TO TOP DENGAN EFEK BOUNCE, CARA MEMBUAT BADGE GOOGLE PLUS DAN DAPAT DI MODIFIKASI, MACAM TAG KONDISIONAL UNTUK MODIFIKASI TAMPILAN DAN MENYEMBUNYIKAN WIDGET, CARA MEMBUAT CATATAN KAKI SEO DAN TERINDEX GOOGLE, TIPS TRIK MEMPERCEPAT LOADING BLOG, TIPS TRIK MENDAPATKAN UANG DOLLAR DARI BLOGGER BLOGSPOT, CARA MEMBUAT THREADED COMMENTS VALID HTML5 DI BLOGGER, MEMBUAT ARTIKEL TERKAIT DISERTAI THUMBNAIL GAMBAR, JQUERY SLIDING PANEL DENGAN MEMBUKA MENUTUP UNTUK BLOGGER, CARA MEMBUAT STICKY WIDGET SIDEBAR DI BLOG, CARA MEMASANG TRANSLATE DENGAN GAMBAR BENDERA DI BLOG, FASTESEO SEO RESPONSIVE BLOGGER TEMPLATE, 6 RAHASIA CARA SAYA MENINGKATKAN RANKING ALEXA, DOWNLOAD TEMPLATE BLOGSPOT SEO RESPONSIVE PREMIUM, Cara memasang widget, download template blog anime, SSH PREMIUM, SSH GRATIS, OPEN SSH, Config HI Axis100Config HI Indosat, Config HI Smartfreen, Config HI Telkomsel, Config HI Three 3, Config HI XL, Config KPN Tunnel Ultimate, Config KPN Tunnel Ultimate Axis, Config KPN Tunnel Ultimate Telkomsel, Config KPN Tunnel Ultimate Three, Config OpenVPN Axis, Config OpenVPN Indosat, Config OpenVPN Three 3, Config OpenVPN XL
0 Komentar untuk "Introducing the ExifInterface Support Library"