离子3压缩图像

ewi*_*ard 6 javascript compression image typescript ionic-framework

我一直试图用Ionic 3压缩图像客户端2天.我试过了:

ng2-img-max- 使用blue-imp-canvas-to-blob canvas.toBlob()方法时抛出错误(依赖性ng2-img-max).它只告诉我错误发生在哪一行.我想我已经读过,创造一个HTMLCanvasElement离子是不可能的 - 与此有关webworkers.

Ahdin - JS library JIC - JS library TinyJPG - npm module

这些都抛出了各种错误,在研究它们之后我确定了它,因为库/模块与Ionic 3不兼容.我认为很多时候它是一个问题HTMLCanvasElement.

我在这个问题中尝试了这个建议- 但改变quality变量并没有改变图像的大小.

有没有人使用Ionic 3成功压缩客户端图像?你是怎么做到的?

Swa*_*twa 8

尝试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
}
Run Code Online (Sandbox Code Playgroud)

  • 谢谢......是否需要成为压缩工作的png?或者是目标宽度/高度? (2认同)