在我的 Android 应用程序中,我必须以缩小的尺寸(100 KB)以缩略图 View 显示图像,而不是以原始尺寸(1 MB)显示图像。它有助于提高我的应用程序的性能。
如何使用 Ionic/Cordova 实现此压缩功能。您能否提供一些实现此功能的建议。
最佳答案
试试这个。它应该有效。但使用 Canvas 标签代替图像标签。将此代码放入您的 javascript 函数中以加载图像。它将您的图像压缩到您想要的尺寸。
img = new Image();
img.src = 'example.png'; // your file
img.onload = function(){
var canvas = document.getElementById('outputImage'); // id of your canvas
var ctx = canvas.getContext('2d');
canvas.width=400 // your dimensions
canvas.height=300
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
};
关于javascript - 如何使用 Cordova 在缩略图中显示缩小尺寸的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38049706/