它只是沿着顶部和左侧边缘画一条红线,我不明白为什么。嵌套的 for 循环不应该遍历每个可能的 x,y 坐标吗?
function createSquare() {
var height = 50;
var width = 50;
var img = new PNGlib(width, height, 256);
var background = img.color(0, 0, 0, 0);
for (var x = 0; x <= width; x ++) {
for (var y = 0; y <= height; y ++) {
img.buffer[img.index(x, y)] = img.color(0xFF, 0x00, 0x00);
}
}
return ('<img src="data:image/png;base64,' + img.getBase64() + '">');
}