javascript - Ionic 3 压缩图像

标签 javascript image typescript ionic-framework compression

我已经尝试使用 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/

相关文章:

html - href图片链接点击下载

web-services - 使用 typescript 使用 Web 服务

javascript - Ember CLI Hook /事件错误

html - 尝试使用 CSS 调整 img 的大小,不响应任何大小属性

html - 谷歌浏览器 40 版 srcset 属性问题

angular - 如何从 typescript 中的字符串中删除空格?

javascript - 我无法在其他 Node 模块工作时导入其中一个 Node 模块

javascript - 鼠标悬停或悬停 vue.js

javascript - 旋转 90/-90 度的图像模糊 jquery 旋转

javascript - jQuery Animate 在滚动时不起作用