1
我对Ionic 2,Cordova &手机相对较新。我遵循示例应用程序构建了一个简单的相机应用程序。它与其他几个问题中的代码非常相似。在我的android手机上运行,相机拍摄照片,但不显示图像。显示“takePicture fired”日志条目,但没有其他日志条目。有什么我失踪像权限问题?无法理解为什么我甚至没有看到日志条目。Ionic 2相机不能在手机上工作
相关代码:
的mypage.html
<button ion-button block color="primary" (click)="takePicture()">Take Picture</button>
...
<img [src]="base64Image" *ngIf="base64Image" />
mypage.ts
export class MyPage {
public base64Image: string;
constructor(public navCtrl: NavController) {
}
takePicture() {
console.log("takePicture fired.");
Camera.getPicture({
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 1000,
targetHeight: 1000
}).then((imageData) => {
// imageData is a base64 encoded string
this.base64Image = "data:image/jpeg;base64," + imageData;
if (this.base64Image) {
console.log("base64Image = " + this.base64Image);
}
else {
console.log("base64Image = NULL");
}
}, (err) => {
console.log("An error occurred.");
console.error(err);
});
});