Phonegap - 将图像捕获到照片库并以 HTML 格式显示

发布于 2024-12-28 16:51:56 字数 879 浏览 4 评论 0原文

我一直在使用下面的代码来抓取照片并以 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

现在将图像捕获到库中,但

  1. 不再显示在 html 中
  2. 不再允许我在相机中拍摄照片后编辑照片'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

  1. no longer displays in html
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里南柯 2025-01-04 16:51:56

当 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文