372 Star 2.1K Fork 834

HarmonyOS-Cases/Cases

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
camera.html 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
haoxiaohui 提交于 2024-02-23 17:57 +08:00 . Web组件拉起原生相机案例
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8">
<style>
body {
font-family: Arial, Helvetica, sans-serif, sans-serif;
text-align: center;
background-color: #f2f2f2;
padding: 20px;
}
#image {
display: none;
max-width: 100%;
height: auto;
margin-top: 15px;
}
#image_preview {
display: none;
margin-top: 15px;
}
</style>
</head>
<body>
<script>
// 显示ArkTS返回的图片
function showPic() {
// input标签的onchange事件触发时,返回的的描述事件所有相关信息的对象,此处接收ArkTS中onShowFileSelector接口的返回结果
let event = this.event;
let tFile = event ? event.target.files : [];
// 如果返回的图片列表是空的,则不显示
if (tFile === 0) {
document.getElementById('image_preview').style.display = 'block';
document.getElementById('image_preview').innerHTML = "未选择图片";
return;
}
document.getElementById('image').setAttribute('src', URL.createObjectURL(tFile[0]));
document.getElementById('image_preview').style.display = 'block';
document.getElementById('image').style.display = 'block';
}
</script>
<input ref="camera" type="file" id="upload" name="upload" accept="image/*" capture="upload" onchange="showPic()" />
<p id="image_preview">图片预览</p>
<img id="image">
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/harmonyos-cases/cases.git
git@gitee.com:harmonyos-cases/cases.git
harmonyos-cases
cases
Cases
master

搜索帮助