gpt4 book ai didi

ios - 使用 Phonegap 显示最近捕获的图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:26 24 4
gpt4 key购买 nike

我希望能够通过按钮 <button onclick="showImage();">Show Image</button><br> 显示最近捕获的图像,但不确定如何执行此操作,而且我在 Phonegap API 中找不到有关它的任何有用信息。基本上就是函数 showImage();我需要帮助创建。

捕获图像的代码正在正确执行,我运行的是 iOS 6。

Phonegap/ Cordova :

  <title>Capture Image</title>

<script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>
<script type="text/javascript" charset="utf-8" src="json2.js"></script>
<script type="text/javascript" charset="utf-8">

var captureSuccess = function(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
readDataUrl = mediaFiles[i].fullPath;

}
};

function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
document.getElementById('errormsg').innerHTML = msg;
}

function captureImage(){
document.getElementById('format-data').innerHTML = "";
document.getElementById('capture-result').innerHTML = "";
navigator.device.capture.captureImage(captureImageSuccess, captureError, {limit: 1});
}

}

function captureImageSuccess(mediaFiles) {
var i, len;

var formatSuccess = function (mediaFiles) {
document.getElementById('format-data').innerHTML =
"Height: <strong>" + mediaFiles[i].height + "</strong><br/>" +
"Width: <strong>" + mediaFiles[i].width + "</strong><br/>";
};
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
// uploadFile(mediaFiles[i]);
document.getElementById('capture-result').innerHTML = "<br/><strong>" + (i+1) + " file<br/> Path: " + mediaFiles[i].fullPath + "</strong><br/>" +
"Height: <strong>" + mediaFiles[i].height + "</strong><br/>" +
"Width: <strong>" + mediaFiles[i].width + "</strong><br/>";
mediaFiles[i].getFormatData(formatSuccess, formatError);
}
console.log("captureImageSuccess");
}


</script>

</head>

HTML:

<body>
<button onclick="captureImage();">Capture Image</button> <br>
<button onclick="showImage();">Show Image</button><br>
<div class="result-block">
Capture Result: <span id="capture-result"></span><br/>
<span id="errormsg"></span>
</div>


</body>
</html>

最佳答案

你已经有了图片的完整路径,只需创建一个 img 元素即可:

<img id="picResult" />

并在您的 javascript 中设置它的 url,只要您收到回复:

var formatSuccess = function (mediaFiles) {
document.getElementById('format-data').innerHTML =
"Height: <strong>" + mediaFiles[i].height + "</strong><br/>" +
"Width: <strong>" + mediaFiles[i].width + "</strong><br/>";

//HERE:
document.getElementById('picResult').src = mediaFiles[i].fullPath;

};

关于ios - 使用 Phonegap 显示最近捕获的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14224878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com