如何从可绘制图像中剪切一些像素?比如,我有一个单杠,我只想显示该单杠的 50%。我该怎么做?
最佳答案
这是从给定图像裁剪图像的方式:
// 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));
}
}
对于您的问题,只需创建一个宽度和高度等于给定图像宽度和高度一半的图像,然后在您想要的任何位置设置任何像素!
关于Android - 以编程方式剪切可绘制图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12318786/