Ionic 2 - 是否可以通过移动浏览器使用相机?
Ionic 2 - Is possible to use camera through mobile browser?
我使用 ionic 2 开发了一个网络应用程序,但 cordova 相机无法在移动浏览器上运行
我需要这个问题的解决方案来让我拍摄照片吗?
我找到了这个解决方案,但不是我想要的
<input type="file" ..>
我想在点击按钮时打开相机
我看到 Instagram 网站 www.instagram.com 允许用户通过浏览器拍摄照片,但我找不到与此主题相关的解决方案
您是否已经尝试过 Cordova plugin 相机?
我用离子按钮内的 <input type="file" ..>
解决了它,并在文件输入中添加了一个特殊的 css 使其不可见:
<button ion-button default icon-left round>
<input type="file" class="file-input" (change)="picChange($event)" accept="image/gif, image/jpeg, image/png">
<ion-icon name="camera"></ion-icon>
Select picture
</button>
和 css 文件:
.file-input {
opacity: 0;
position: absolute;
top: 0;
width: 100%;
height: 100%;
left: 0;
z-index: 999;
}
您将在您的 .ts 中引用该文件,如下所示:
picChange(event: any) {
let file = event.srcElement.files[0];
//you can do anything with this file
}
如果您在移动浏览器中看到结果,它会询问您是用相机拍照,还是使用照片库,还是浏览文件。
我使用 ionic 2 开发了一个网络应用程序,但 cordova 相机无法在移动浏览器上运行
我需要这个问题的解决方案来让我拍摄照片吗?
我找到了这个解决方案,但不是我想要的
<input type="file" ..>
我想在点击按钮时打开相机
我看到 Instagram 网站 www.instagram.com 允许用户通过浏览器拍摄照片,但我找不到与此主题相关的解决方案
您是否已经尝试过 Cordova plugin 相机?
我用离子按钮内的 <input type="file" ..>
解决了它,并在文件输入中添加了一个特殊的 css 使其不可见:
<button ion-button default icon-left round>
<input type="file" class="file-input" (change)="picChange($event)" accept="image/gif, image/jpeg, image/png">
<ion-icon name="camera"></ion-icon>
Select picture
</button>
和 css 文件:
.file-input {
opacity: 0;
position: absolute;
top: 0;
width: 100%;
height: 100%;
left: 0;
z-index: 999;
}
您将在您的 .ts 中引用该文件,如下所示:
picChange(event: any) {
let file = event.srcElement.files[0];
//you can do anything with this file
}
如果您在移动浏览器中看到结果,它会询问您是用相机拍照,还是使用照片库,还是浏览文件。