Android-从某个点开始剪切位图
我一直在这里搜索android中的剪切位图,但是我无法让它为我工作。 我想切掉一个特定位图的某些部分,但我想从图像的中心到底部切掉 我已经尝试使用: createBitmap(android.graphics.Bitmap源代码、整数x、整数y、整数宽度、整数高度) 但是,它总是从顶部开始剪切图像,甚至更改x和y值。 我想把我的位图剪成蓝色方块 有人知道如何剪切我的位图吗?试试这个:Android-从某个点开始剪切位图,android,bitmap,Android,Bitmap,我一直在这里搜索android中的剪切位图,但是我无法让它为我工作。 我想切掉一个特定位图的某些部分,但我想从图像的中心到底部切掉 我已经尝试使用: createBitmap(android.graphics.Bitmap源代码、整数x、整数y、整数宽度、整数高度) 但是,它总是从顶部开始剪切图像,甚至更改x和y值。 我想把我的位图剪成蓝色方块 有人知道如何剪切我的位图吗?试试这个: Bitmap source = BitmapFactory.decodeResource(getResourc
Bitmap source = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
int width = source.getWidth();
int height = source.getHeight();
int required = 25;// 25 pixels width and height
int startX = (width - required) / 2;
int startY = (height - required) / 2;
Bitmap resized = Bitmap.createBitmap(source, startX, startY, required,
required);
唯一相关的部分是startX和startY计算。代码表明您需要一个25*25像素的图像。您应该看看这个:
private Bitmap cropBitmap1()
{
Bitmap bmp2 = BitmapFactory.decodeResource(this.getResources(), R.drawable.image1);
Bitmap bmOverlay = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
Paint p = new Paint();
p.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
Canvas c = new Canvas(bmOverlay);
c.drawBitmap(bmp2, 0, 0, null);
c.drawRect(30, 30, 100, 100, p);
return bmOverlay;
}
链接: