我正在使用“ Cordova插件相机”,它的工作范围是可以拍摄一张或多张图片,并使用来在单独的窗口中显示它们。但是我想使用高级信号处理技术来处理图像,因此我需要2D阵列中的像素。我使用png格式来避免压缩,而使用“ Cordova插件get-pixels”来获取nDarray。问题是将两者连接。我目前的相关代码是:
function takePicture(val) // called by <button>
{
imageNum = val; // a global variable
theCamera.callCamera();
};
然后调用:
var theCamera =
{
image: null,
imgOptions:null,
initialize: function()
{
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function()
{
console.log('camera onDeviceReady: ',cordova.file);
theCamera.image = document.querySelector(theImage);
},
callCamera: function ( )
{
theCamera.imgOptions =
{
quality : 100,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit : false,
encodingType : Camera.EncodingType.PNG,
mediaType: Camera.MediaType.PICTURE,
targetWidth : 512,
targetHeight : 512,
correctOrientation: true,
cameraDirection : Camera.Direction.FRONT,
saveToPhotoAlbum : false
};
navigator.camera.getPicture( theCamera.imgSuccess, theCamera.imgFail, theCamera.imgOptions );
},
imgSuccess: function ( imageData )
{
// image returned from camera
console.log("imageData",imageData)
getPixels(imageData, function(err, pixels) {
if(err) {
console.log("Bad image path")
return
}
console.log("got pixels", pixels.shape.slice())
})
…
成功获取图像会产生“ imageData”,如下所示:
[Log] imageData – "file:///var/mobile/Containers/Data/Application/993D18CE-C577-45DA-A77C-4479D931C634/tmp/cdv_photo_003.png" (cordova.js, line 1732)
但是尝试使用getPixels()会导致:
[Error] Origin null is not allowed by Access-Control-Allow-Origin.
[Error] Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin. (cdv_photo_003.png, line 0)
[Error] Cross-origin image load denied by Cross-Origin Resource Sharing policy.
[Log] Bad image path (cordova.js, line 1732)
getPixels()无法访问navigator.camera.getPicture()生成的文件会导致错误消息“错误的图像路径”。
我认为也许使用“ Cordova插件文件”读取文件或先写入然后读取文件可能会解决此问题,但似乎是一个round回的解决方案。有没有更简单的方法?
目标是在平板电脑上安装一个独立的应用程序:iOS和Android。