我已经尝试使用 Ionic 3 在客户端压缩图像 2 天了。我试过:
ng2-img-max
- 使用 blue-imp-canvas-to-blob
canvas.toBlob()
时抛出错误方法(ng2-img-max
的依赖项)。它只是告诉我错误发生在哪一行。我想我已经读过在 Ionic 中创建 HTMLCanvasElement
是不可能的 - 这与 webworkers
有关。
Ahdin - JS 库
JIC - JS 库
TinyJPG - npm 模块
这些都引发了各种错误,在研究它们之后我确定这是因为库/模块与 Ionic 3 不兼容。我认为很多时候这是 HTMLCanvasElement
的问题。
我尝试了 this 中的建议问题 - 但更改 quality
变量不会更改图像的大小。
有没有人使用 Ionic 3 在客户端成功压缩图像?你是怎么做到的?
最佳答案
尝试使用 camera plugin 跟随 CameraOptions
.
const options: CameraOptions = {
quality: 20,
targetWidth: 600,
targetHeight: 600,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.PNG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: true //may not work with some deices
}
关于javascript - Ionic 3 压缩图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45266483/