以画布绘图以编程方式使图像移动

时间:2017-02-24 23:04:30

标签: android canvas

我正在做一个应用程序,我将图像加载到ImageView中,之后我在ImageView上绘制了多个50x50像素的正方形。这就是我所说的:

enter image description here

enter image description here

我用来制作正方形的代码是这样的:

    private void splitImage() {


    Bitmap aux = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(aux);
    imgView.draw(c);

    Paint p = new Paint();
    p.setColor(Color.BLACK);

        for (int xCoord = 0; xCoord < width; xCoord += 50) {

            c.drawLine(xCoord, 0, xCoord, height, p);

        }

    for (int yCoord = 0; yCoord < height; yCoord+=50){

        c.drawLine(0, yCoord, width, yCoord, p);

    }

    imgView.setImageResource(0);

    imgView.setImageBitmap(aux);

}

你之前看到过这个问题吗?

1 个答案:

答案 0 :(得分:0)

在@pskink的帮助下,问题解决了。而不是imgView.draw(c)我使用了c.drawBitmap(bm,0,0,p);