我使用fabricjs在我的图像中应用了反转、灰度和其他过滤器,然后图像质量就会下降。请查看下面的代码,如果代码有任何问题,请告诉我。我使用图像(img)作为填充矩形的图案。
var filters = ['brightness','grayscale', 'invert', 'sepia', 'sepia2','blur', 'sharpen'];
var applyFilter = function(index, filter) {
img.filters[index] = filter;
img.applyFilters(canvas.renderAll.bind(canvas));
}
var applyFilterValue = function(index, prop, value) {
if (img.filters[index]) {
img.filters[index][prop] = value;
img.applyFilters(canvas.renderAll.bind(canvas));
}
}
img.filters[0] = new filter.Brightness({'brightness': 0});
$('body').on('click', '#blackwhite', function() {
applyFilter(1, this.checked && new filter.Grayscale());
});
$('body').on('click', '#invert', function() {
applyFilter(2, this.checked && new filter.Grayscale());
});