3

如何从可绘制图像中剪切一些像素?就像,我有一个单杠,我只想显示那个单杠的 50%。我怎样才能做到这一点?

4

1 回答 1

-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));
    }
}

对于您的问题,只需创建一个宽度和高度等于给定图像宽度和高度一半的图像,然后在您想要的任何位置设置任何像素!

于 2012-09-07T13:50:51.180 回答