PhoneGap的/科尔多瓦摄像头插件 - 如何让照片的日期/时间戳记? [英] Phonegap / Cordova camera plugin - how to get photo's date/time stamp?

查看:429
本文介绍了PhoneGap的/科尔多瓦摄像头插件 - 如何让照片的日期/时间戳记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PhoneGap的应用程序,需要让用户既需要使用手机的摄像头的照片,让用户在照片的设备上已经有了选择。

I have a Phonegap app that needs to let the user both take photos using the phone's camera and let the user select from photo's already on the device.

我需要捕捉照片的拍摄作为元数据的一部分的日期/时间,但我有一个很难搞清楚如何与PhoneGap的/科尔多瓦做到这一点。

I need to capture the date/time the photo was taken as part of the metadata, but I'm having a hard time figuring out how to do this with Phonegap / Cordova.

起初,我以为我可以使用File API的FileEntry.getMetadata()调用,但这并不返回一个有效日期modificationTime属性。我认为的PhoneGap也转换设备上的文件,以便您收到从相机插件背面是不是在设备上的原文件,这样即使的getMetaData()调用的工作,日期不会是正确的。

Initially I thought I could use the File API's FileEntry.getMetadata() call but this doesn't return a valid date for the modificationTime attribute. I think that phonegap also transforms the file on the device so that the you recieve back from the camera plugin is not the original file on the device, so even if the getMetadata() call worked, the date wouldn't be the correct one.

有没有解决这个其他方式,总之写我自己的版本,摄像头的插件的,我需要每个平台的?

Is there any other way around this, short of writing my own version of the camera plugin for each platform I need?

太疯狂了,这将是解决它的唯一办法。

Seems crazy that this would be the only way around it.

推荐答案

所以,我已经成功地想出解决办法。

So, I've managed to figure this out.

随着一堆其他信息的日期/时间标记可以检索从JPEG文件中的EXIF数据标签。这可以使用这个有用的JS库来完成 - https://github.com/jseidelin/exif-js

The date/time stamp along with a bunch of other information can be retrieved from the EXIF data tags inside the JPEG file. This can be done using this helpful JS library - https://github.com/jseidelin/exif-js

不幸的是,科尔多瓦相机插件Android的转变从库中选择图像时,用相机拍摄的图像,只有当,所以这是一个问题,不会复制EXIF标签,但我会通过派生插件解决这个问题。 iOS的版本的插件,似乎这样做正确的事情。

Unfortunately the Cordova camera plugin for Android doesn't copy EXIF tags when transforming an image selected from the gallery, only when taking an image using the camera, so this is a problem, but I will fix this by forking the plugin. The iOS version of the plugin seems to do this right thing.

code,有兴趣的 -

Code for anyone interested -

var source = fromCamera 
       ? Camera.PictureSourceType.CAMERA 
       : Camera.PictureSourceType.PHOTOLIBRARY;

var opts = {
    encodingType: Camera.EncodingType.JPEG,
    sourceType: source,
    destinationType: Camera.DestinationType.NATIVE_URI
};

navigator.camera.getPicture(
        function(imageURI) {
            window.resolveLocalFileSystemURL(imageURI,
                    function(entry) {
                        entry.file(function(file) {
                            EXIF.getData(file, function() {
                                var datetime = EXIF.getTag(this, "DateTimeOriginal");
                                alert(datetime);
                            });                                                

                            // do something useful....

                        }, standardErrorHandler);
                    },
                    function(e) {
                        alert('Unexpected error obtaining image file.');
                        standardErrorHandler(e);
                    });
        },
        function() {
            // nada - cancelled
        },
        opts);

这篇关于PhoneGap的/科尔多瓦摄像头插件 - 如何让照片的日期/时间戳记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆