我正在通过 Cordova 相机 API 在 ios 设备上抓取相机图像,然后通过localforage
. 但是,似乎没有加载资源,因为单击Resources
标记下的 blobSafari Web Inspector
显示An error occured while trying to load resources
错误,并且图像呈现为20x20
白色背景而不是照片。这是我的 HTML 包装器Cordova Camera API
:
<head>
<title>Capture Photo</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="js/camera.js"></script>
<script type="text/javascript" charset="utf-u" src="js/localforage.js"></script>
<script type="text/javascript">
function savePhoto(contents){
localforage.setItem('photo', contents, function(img) {
// This will be a valid blob URI for an <img> tag.
var blob = new Blob([img], { type: "image/jpeg" } );
var imageURI = window.URL.createObjectURL(blob);
console.log(imageURI);
var newImg = document.createElement("img");
newImg.src=imageURI;
// add the newly created element and its content into the DOM
var currentDiv = document.getElementById("div1");
document.body.insertBefore(newImg, currentDiv);
});
console.log(contents.byteLength);
}
function grabPhoto(){
capturePhotoEdit(savePhoto,function(e){console.log(e);});
}
</script>
</head>
<body>
<button onclick="grabPhoto();">Capture Photo</button> <br>
<div id="div1"> </div>
</body>
</html>
我们savePhoto
用来保存从相机抓取的图像(在 中js/camera.js
)。控制台记录blob
打印出诸如blob:null/916d1852-c8c5-4b3b-ac8c-86b6c71d0e86
.
我将非常感谢有关我在图像渲染方面做错了什么的指示。