0

所以我正在尝试使用 jCanvas 在 html 中构建一个带有像素艺术的游戏。但是,当我尝试禁用 imageSmoothing 以使像素保持清晰时,什么也没有发生。

$(function() {
    $('canvas').drawImage({
        source: 'http://i.imgur.com/Y2o59.png',
        x:400, y:250,
        width: 160, height: 160,
        imageSmoothingEnabled: false,
    });
});

编辑:添加了随机的像素艺术,使其更容易测试。

4

1 回答 1

0

弄清楚了。

首先,它的imageSmoothing: false,不是imageSmoothingEnabled: false。其次,您仍然需要在上下文中启用平滑,如下所示:

var ctxbgd = document.getElementById('background').getContext("2d");
    ctxbgd.imageSmoothingEnabled = false;
    ctxbgd.webkitImageSmoothingEnabled = false;
    ctxbgd.mozImageSmoothingEnabled = false;

那里,没有平滑。

于 2014-11-14T01:56:15.523 回答