【发布时间】:2019-07-19 11:50:13
【问题描述】:
所以目前我手机摄像头的图像尺寸太大了。
我正在使用 cordova-camera-preview-plugin,保存文件并使用 Ionic Native File 将其移动到永久位置。
现在我正在尝试使用 ng2-img-tools 来调整图像大小,但它抱怨图像不是 png/jpg。
我认为这是因为 ng2-img-tools 需要一个文件,而我正在传递图像的位置。那么有人知道如何解决这个问题吗?
任何帮助表示赞赏。
import { File } from '@ionic-native/file/ngx';
import { Ng2ImgToolsService } from 'ng2-img-tools';
import { CameraPreview, CameraPreviewPictureOptions } from '@ionic-native/camera-preview/ngx';
constructor(private file: File, public cameraPreview: CameraPreview, private ng2ImgToolsService: Ng2ImgToolsService) { }
takePhoto()
{
this.cameraPreview.takePicture({quality: .7}).then((path) => {
let tempPath = path[0].substr(0, path[0].lastIndexOf('/') + 1);
let tempFileName = path[0].replace(tempPath, "");
let fullTempPath = 'file://' + tempPath;
var newFilename = this.createFileName();
var permLocation = this.file.dataDirectory + newFilename;
// Copy Image to Perm Directory....
this.file.copyFile(fullTempPath, tempFileName, this.file.dataDirectory, newFilename).then(success => {
var localLocation = window.Ionic.WebView.convertFileSrc(permLocation);
this.ng2ImgToolsService.resize([localLocation], 640, 640).subscribe(result => {
//all good, result is a file
console.info(result);
}, error => {
});
}, error => {
});
}, error => {
});
}
【问题讨论】:
标签: angular cordova ionic-framework image-processing