本文介绍了使用智能手机时,检测加载图像是否直接从相机拍摄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用html,标记:

 < input type =file/& 

在Android和许多移动设备上,我有能力通过拍摄照片并直接获取文件



我如何知道(通过javascript代码)如何获取图片(直接通过相机,或通过我的蜂窝上的一些文件)?

我做了一些工作,发现exif(),但我没有成功使用它来动态加载图片,如网站:
需要一些源代码示例,以了解exif如何在动态加载的图像上工作。



感谢:)

解决方案

我自己找到了解决方案,想要参与它:



我需要的是将二进制数据转换为exif数据,
等等在exif.js上,我添加了以下内容。

  jQuery.fn.getExif = function(){
var exif;
var bin;
var bf;
bin = atob(this.attr(src)。split(',')[1]);
if(bin){
bf = new BinaryFile(bin);
}
if(bf){
exif = EXIF.readFromBinaryFile(bf);
}
if(exif){
this.attr(exifdata,exif);
}
return exif;
}

并使用上面的代码 - 只是得到任何exif值。 / p>

主要的问题是图像应该根据exif
旋转(如果,方向是顺时针90度,所以我应该逆时针旋转90度



IPAD(或者是IPAD) Safari - 我不知道确切的问题在哪里)帮我一个忙,并自动旋转图像,当我从文件加载它,所以它总是正确显示。



现在我如何知道何时旋转图片,何时不旋转图片。



感谢:)


I am using html, tag:

<input type = "file" />

On android and on many cellulars I have the ability to get the file directly by taking a picture and save it.

How can I know (by javascript code) how did I get the picture (direcly by the camera, or by some files that on my cellular)?

I did some workarround, and found exif (http://www.nihilogic.dk/labs/exif/exif.js), but I didn't succeed using it for images loading dynamically, as the site : http://exif-viewer.com/ Need some source code examples, to understand how exif works on dynamically loaded images.

Thanks :)

解决方案

I have found the solution by myself, so I want to participate it:

What I needed is translate the binary data to exif data,so on exif.js, I added the following.

jQuery.fn.getExif = function() {
    var exif;
    var bin;
    var bf;
    bin = atob(this.attr("src").split(',')[1]);
    if (bin) {
        bf = new BinaryFile(bin);
    }
    if (bf) {
        exif = EXIF.readFromBinaryFile(bf);
    }
    if (exif) {
        this.attr("exifdata", exif);
    }
    return exif;
}

and use the above on code - just get any exif value I want.

The main issue is that the image should be rotated according to exif(if, i.e. the orientation is 90 degrees clockwise, so I should rotate 90 counterclockwise, in order to fix the orientation) - No problem on most devices,but there is a problem that persists on several devices, such as IPAD.

IPAD (or Safari - I don't know exactly where might be the problem) do me a favour, and auto rotate the image, when I am loading it from file, so it is displayed always correctly.

Now how can I know when to rotate the image and when not rotating it.

Thanks :)

这篇关于使用智能手机时,检测加载图像是否直接从相机拍摄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 18:15