3
如何從可繪製圖像剪切一些像素?就像,我有一個單槓,我只想顯示該欄的50%。我怎樣才能做到這一點?Android - 以編程方式剪切可拖動圖像
如何從可繪製圖像剪切一些像素?就像,我有一個單槓,我只想顯示該欄的50%。我怎樣才能做到這一點?Android - 以編程方式剪切可拖動圖像
這是你如何從給定的圖像裁剪圖像:
// 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));
}
}
對於您的問題,只需創建一個寬度和高度的圖像相當於您定圖像的寬度和高度的一半,然後設置任何像素在任何你想要的地方!
但我必須直接裁剪一個Drawable對象。也許使用可繪製級別的工作?但是我不知道如何使用Drawable對象上的關卡。 –