내 문제를 재현하기 위해 this fiddle을 사용하고 있습니다. 버전 57의 Android 용 Chrome을 사용하면 크기가 조정 된 이미지가 매우 어두워집니다. 이미지 크기를 충분히 조정하면 (전화와 전화기에 따라 다름) 어둡기가 사라지고 이미지 크기가 올바르게 조정됩니다.Android 용 Chrome을 사용하여 캔버스에서 크기를 조정하면 이미지가 왜 어두워 집니까?
누구나 어떤 이상한 행동을 일으킬 수있는 아이디어가 있습니까? Chromium에 filed a bug이 있지만 곧 해결 될 것으로 기대하지 않습니다. 그리고 제작시이 코드를 사용하고 있으며 이로 인해 심각한 문제가 발생하기 때문에 가능한 한 빨리 수정해야합니다.
가 SO 내가 jsfiddle하는 링크를 사용했기 때문에 나를, 몇 가지 코드를 넣어 원하는, 그래서 이것은 내가 HTML5 캔버스를 사용하여 이미지 크기 조정에 사용이 문제의 원인이되는 코드의 일부입니다
/**
* Hermite resize - fast image resize/resample using Hermite filter. 1 cpu version!
*
* @param {HtmlElement} canvas
* @param {int} width
* @param {int} height
* @param {boolean} resize_canvas if true, canvas will be resized. Optional.
*/
this.resample_single = function (canvas, width, height, resize_canvas) {
var width_source = canvas.width;
var height_source = canvas.height;
width = Math.round(width);
height = Math.round(height);
var ratio_w = width_source/width;
var ratio_h = height_source/height;
var ratio_w_half = Math.ceil(ratio_w/2);
var ratio_h_half = Math.ceil(ratio_h/2);
var ctx = canvas.getContext("2d");
var img = ctx.getImageData(0, 0, width_source, height_source);
var img2 = ctx.createImageData(width, height);
var data = img.data;
var data2 = img2.data;
for (var j = 0; j < height; j++) {
for (var i = 0; i < width; i++) {
var x2 = (i + j * width) * 4;
var weight = 0;
var weights = 0;
var weights_alpha = 0;
var gx_r = 0;
var gx_g = 0;
var gx_b = 0;
var gx_a = 0;
var center_y = (j + 0.5) * ratio_h;
var yy_start = Math.floor(j * ratio_h);
var yy_stop = Math.ceil((j + 1) * ratio_h);
for (var yy = yy_start; yy < yy_stop; yy++) {
var dy = Math.abs(center_y - (yy + 0.5))/ratio_h_half;
var center_x = (i + 0.5) * ratio_w;
var w0 = dy * dy; //pre-calc part of w
var xx_start = Math.floor(i * ratio_w);
var xx_stop = Math.ceil((i + 1) * ratio_w);
for (var xx = xx_start; xx < xx_stop; xx++) {
var dx = Math.abs(center_x - (xx + 0.5))/ratio_w_half;
var w = Math.sqrt(w0 + dx * dx);
if (w >= 1) {
//pixel too far
continue;
}
//hermite filter
weight = 2 * w * w * w - 3 * w * w + 1;
var pos_x = 4 * (xx + yy * width_source);
//alpha
gx_a += weight * data[pos_x + 3];
weights_alpha += weight;
//colors
if (data[pos_x + 3] < 255)
weight = weight * data[pos_x + 3]/250;
gx_r += weight * data[pos_x];
gx_g += weight * data[pos_x + 1];
gx_b += weight * data[pos_x + 2];
weights += weight;
}
}
data2[x2] = gx_r/weights;
data2[x2 + 1] = gx_g/weights;
data2[x2 + 2] = gx_b/weights;
data2[x2 + 3] = gx_a/weights_alpha;
}
}
//clear and resize canvas
if (resize_canvas === true) {
canvas.width = width;
canvas.height = height;
} else {
ctx.clearRect(0, 0, width_source, height_source);
}
//draw
ctx.putImageData(img2, 0, 0);
};