Phonegap - 将图像捕获到照片库并以 HTML 格式显示
我一直在使用下面的代码来抓取照片并以 html 形式显示它,效果非常好。
function takePicture() {
navigator.camera.getPicture(
function(uri) {
var img = document.getElementById('camera_image1');
img.style.visibility = "visible";
img.style.display = "block";
img.src = uri;
document.getElementById('camera_status').innerHTML = "Success";
},
{ quality: 50, allowEdit: true, destinationType: navigator.camera.DestinationType.FILE_URI});
};
html 稍后
<img style="width:144px;height:144px;" id="camera_image1" src="nophoto.jpg"/>
但是...这不会将图像保存到相机照片库中,所以我将行调整为
navigator.device.capture.captureImage
现在将图像捕获到库中,但
- 不再显示在 html 中
- 不再允许我在相机中拍摄照片后编辑照片'app'
非常感谢任何指针。
电话间隙1.3
I have been using the following code to grab a photo and display it in html works great.
function takePicture() {
navigator.camera.getPicture(
function(uri) {
var img = document.getElementById('camera_image1');
img.style.visibility = "visible";
img.style.display = "block";
img.src = uri;
document.getElementById('camera_status').innerHTML = "Success";
},
{ quality: 50, allowEdit: true, destinationType: navigator.camera.DestinationType.FILE_URI});
};
html later
<img style="width:144px;height:144px;" id="camera_image1" src="nophoto.jpg"/>
but... this does not save the image to the cameras photo library so I tweaked line to
navigator.device.capture.captureImage
This now captures image to library but
- no longer displays in html
- No longer allows me to edit the photo after I have taken photo in the camera 'app'
Any pointer much appreciated.
PhoneGap 1.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当 captureImage 成功时,它会将一组 MediaFile 对象传递给您的回调(这是一个数组,因为可能有多个结果,但您的示例只有一个)。 MediaFile 对象包含完整路径。您应该能够使用与上面类似的代码来指向文件 uri。
至于你的第二个问题 - 不确定你在这里期望什么。 “图像捕捉”本身并不是编辑。您需要使用 JavaScript 构建自己的编辑器 - 这可能有点过头了。
When captureImage succeeds, it passes an array of MediaFile objects to your callback (an array since it's possible to have more than one result, but your example will only have one). The MediaFile objects contain the full path. You should be able to use code similar to what you have above to point to the file uri.
As to your second question - not sure what you expect here. "Image Capture" isn't editing per se. You would need to build your own editor using JavaScript - which would be overkill probably.