2017-02-24 82 views
0

我正在做一個應用程序,我將圖像加載到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); 

} 

你以前看這個問題?

+0

什麼是寬度和高度?原來的'Bitmap'的大小?如果是這樣,而不是'imgView.draw(c);'use'c.drawBitmap' – pskink

+0

@pskink寬度和高度是圖像在ImageView中顯示的尺寸(以像素爲單位)。我會試着用drawBitmap。謝謝 ! –

+0

似乎如果我使用c.drawBitmap它不顯示任何東西 –

回答

0

在@pskink的幫助下,問題解決了。而不是imgView.draw(c)我使用c.drawBitmap(bm,0,0,p);