Javascript 离子电容器cordova插件无法将图像写入Android上的库
我正在尝试使用安卓版的离子电容器,但在图像被捕获后,当图像裁剪UI应该显示时,它会再次返回到捕获屏幕。这是最新的。这是logcat控制台中似乎相关的内容:Javascript 离子电容器cordova插件无法将图像写入Android上的库,javascript,android,cordova,ionic-framework,capacitor,Javascript,Android,Cordova,Ionic Framework,Capacitor,我正在尝试使用安卓版的离子电容器,但在图像被捕获后,当图像裁剪UI应该显示时,它会再次返回到捕获屏幕。这是最新的。这是logcat控制台中似乎相关的内容: 2020-08-03 13:26:05.320 27707-27707/si.test.app D/ViewRootImpl@9f2e8cd[ScanActivity]:返回的重新启动:旧=(0,010802280)新=(0,010802280)请求=(10802280)4 dur=8 res=0x1 s={false 0}ch=false
2020-08-03 13:26:05.320 27707-27707/si.test.app D/ViewRootImpl@9f2e8cd[ScanActivity]:返回的重新启动:旧=(0,010802280)新=(0,010802280)请求=(10802280)4 dur=8 res=0x1 s={false 0}ch=false 2020-08-03 13:26:05.321 27707-27707/si.test.app D/ViewRootImpl@9f2e8cd[ScanActivity]:已停止(false)old=true 2020-08-03 13:26:05.328 27707-27707/si.test.app W/System.err:java.io.FileNotFoundException:open失败:enoint(没有这样的文件或目录)
2020-08-0313:42:50.7491278-1278/?E/Util:writeImageDataToRequestedUri:创建目录失败或目录已存在。
2020-08-0313:42:50.760 1278-1278/?E/Util:WriteImageDataToRequestDuri:由于outputStream IOException而返回。
这是我的配置:
- 设备:三星Galaxy S10e
- 操作系统:安卓10
- @电容器/铁芯:2.3.0
- @电容器/安卓:2.3.0
- cordova插件文档扫描仪:4.2.5
Cordova和Capactor是否有可能在设备上有不同的文件路径?我在哪里可以解决这个问题?任何帮助都非常宝贵:)我在我的项目中使用Ionic 5和电容器实现了这一点。它是长代码。试试这个,也许能帮你 安装此npms 然后创建服务文件。 例:摄影服务 然后根据您的情况添加以下代码。我在这里添加了完整的代码,因为它包含了所有内容 有两种方法 getImageCam()-从摄影机获取图像>源:CameraSource.camera getImageGall()-从库中获取图像>源:CameraSource.Photos
import { Injectable } from "@angular/core";
import {
Plugins,
CameraResultType,
CameraPhoto,
CameraSource,
} from "@capacitor/core";
import { Crop } from "@ionic-native/crop/ngx";
import { WebView } from "@ionic-native/ionic-webview/ngx";
//import { File } from "@ionic-native/file/ngx";
const { Camera, Filesystem, Storage } = Plugins;
@Injectable({
providedIn: "root",
})
export class PhotoService {
newCapturedImg: any = null;
ImgNameStart: any = "yourName";
formDataImage: any;
cropImage: CameraPhoto;
constructor(private crop: Crop, private webview: WebView) {}
public async getImageCam() {
// Take a photo
const capturedPhoto = await Camera.getPhoto({
resultType: CameraResultType.Uri,
source: CameraSource.Camera,
quality: 100,
// allowEditing: true,
// height: 300,
// width: 300
});
console.log(capturedPhoto);
this.crop
.crop(capturedPhoto.path, {
quality: 100,
})
.then(
(newImage) => {
this.newCapturedImg = this.webview.convertFileSrc(newImage);
//console.log("new image path is: " + newImage);
//console.log("new image webpath is: " + this.newCapturedImg);
this.cropImage = {
path: newImage,
webPath: this.newCapturedImg,
format: "jpeg",
};
const savedImageFile = this.savePicture(this.cropImage);
},
(error) => console.error("Error cropping image", error)
);
}
public async getImageGall() {
// Take a photo
const capturedPhoto = await Camera.getPhoto({
resultType: CameraResultType.Uri,
source: CameraSource.Photos,
quality: 100,
// allowEditing: true,
// height: 300,
// width: 300,
});
this.crop
.crop(capturedPhoto.path, {
quality: 100,
})
.then(
(newImage) => {
this.newCapturedImg = this.webview.convertFileSrc(newImage);
//console.log("new image path is: " + newImage);
//console.log(this.newCapturedImg);
this.cropImage = {
path: newImage,
webPath: this.newCapturedImg,
format: "jpeg",
};
const savedImageFile = this.savePicture(this.cropImage);
},
(error) => console.error("Error cropping image", error)
);
}
private async savePicture(cameraPhoto: CameraPhoto) {
const blobData = await this.readABlob(cameraPhoto);
this.formDataImage = blobData;
}
private async readABlob(cameraPhoto: CameraPhoto) {
const response = await fetch(cameraPhoto.webPath!);
const blob = await response.blob();
console.log("blob --> ", blob);
return blob;
}
createFileName() {
let d = new Date();
let n = d.getTime();
let newFileName = `${this.ImgNameStart + n}.jpg`;
return newFileName;
}
}
interface Photo {
filepath: string;
webviewPath: string;
base64?: string;
}
您可以从任何组件访问这样的服务变量
示例.page.ts
import { PhotoService } from "../../services/photo.service";
import { PhotoService } from "../../services/photo.service";
constructor(public photoService: PhotoService) {}
yourMethod() {
this.photoService.getImageCam() // or getImageGall()
let formDataImage = this.photoService.formDataImage;
let imageName = this.photoService.createFileName();
let urlToImageSrc = this.photoService.newCapturedImg;
}