Android的图片EXIF阅读器的第三方API第三方、阅读器、图片、Android

由网友(尛尛跟屁虫)分享简介:有没有第三部分API为Android读取图像EXIF标签支持API级别从1.5开始。Is there any 3rd part api for android to read exif tags from image which support api level starting from 1.5.推荐答案在元...

有没有第三部分API为Android读取图像EXIF标签支持API级别从1.5开始。

Is there any 3rd part api for android to read exif tags from image which support api level starting from 1.5.

推荐答案

在元数据提取库通过德鲁诺克斯可以很好地用于提取EXIF标签上较早机器人平台的版本,有轻微的修改。我用它在Android 1.6中提取标签的JPEG图像。

The metadata extraction library by Drew Noakes works well for extracting EXIF tags on earlier Android platform versions, with a slight modification. I am using it on Android 1.6 to extract tags from JPEG images.

您需要下载并构建源$ C ​​$ C自己,和包它与你的应用程序。 (我使用的版本2.3.1)进行以下修改 com.drew.imaging.jpeg.JpegMetadataReader

You will need to download and build the source code yourself, and package it with your app. (I'm using release 2.3.1.) Make the following changes to com.drew.imaging.jpeg.JpegMetadataReader:

删除以下import语句:

Remove the following import statement:

进口com.sun.image codec.jpeg.JPEGDe codeParam;

删除下面的方法(这你就不需要在Android):

Delete the following method (which you won't need on Android):

公共静态元数据读取元(JPEGDe codeParam德codeParam){...}

删除 com.drew.metadata.SampleUsage 类,它引用上述删除的方法。同时删除所有的测试包。

Remove the com.drew.metadata.SampleUsage class, which references the method deleted above. Also remove all of the test packages.

这是所有有给它。下面是使用的一个例子 JpegMetadataReader 从存储在SD卡上的JPEG图像提取日期时间标记:

That's all there is to it. Here's an example of using the JpegMetadataReader to extract a date-time tag from a JPEG image stored on the SD card:

import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.exif.ExifDirectory;

// other imports and class definition removed for brevity

public static Date extractExifDateTime(String imagePath)
{
    Log.d("exif", "Attempting to extract EXIF date/time from image at " + imagePath);
    Date datetime = new Date(0); // or initialize to null, if you prefer
    try
    {
        Metadata metadata = JpegMetadataReader.readMetadata(new File(imagePath));
        Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);

        // these are listed in order of preference
        int[] datetimeTags = new int[] { ExifDirectory.TAG_DATETIME_ORIGINAL,
                                         ExifDirectory.TAG_DATETIME,
                                         ExifDirectory.TAG_DATETIME_DIGITIZED };
        int datetimeTag = -1;
        for (int tag : datetimeTags)
        {
            if (exifDirectory.containsTag(tag))
            {
                datetimeTag = tag;
                break;
            }
        }

        if (datetimeTag != -1)
        {
            Log.d("exif", "Using tag " + exifDirectory.getTagName(datetimeTag) + " for timestamp");

            SimpleDateFormat exifDatetimeFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
            datetime = exifDatetimeFormat.parse(exifDirectory.getString(datetimeTag));
        }
        else
        {
            Log.d("exif", "No date/time tags were found");
        }
    }
    catch (Exception e)
    {
        Log.w("exif", "Unable to extract EXIF metadata from image at " + imagePath, e);
    }
    return datetime;
}
阅读全文

相关推荐

最新文章