2012-09-07 31 views

回答

-1

這是你如何從給定的圖像裁剪圖像:

// Given image is named "girl" in drawable folder 
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.girl).copy(Config.ARGB_8888, true); 
// Create a bit map with width and heigh = 100 pixel 
Bitmap image2 = Bitmap.createBitmap(100, 100, Config.ARGB_8888); 
for(int i = 0; i < 100; i++){ 
    for(int j = 0; j < 100; j++){ 
      // Set color of each pixel of created image to color of given image      
      mage2.setPixel(i, j, image.getPixel(i, j)); 
    } 
} 

對於您的問題,只需創建一個寬度和高度的圖像相當於您定圖像的寬度和高度的一半,然後設置任何像素在任何你想要的地方!

+0

但我必須直接裁剪一個Drawable對象。也許使用可繪製級別的工作?但是我不知道如何使用Drawable對象上的關卡。 –

相關問題