切位图的该部分位图、部分

2023-09-12 06:20:03 作者:假戏-/

可能重复:   如何裁剪在Android上的解析图像?

我选择从位图的部分和我在同一个位图复制选定的部分。现在我想复制后删除选定的部分。如何做到这一点?请帮我..

I have selected a portion from the bitmap and i am copying the selected portion in the same bitmap.. Now i want to remove the selected portion after copying.. How to do it?? please help me out..

推荐答案

最简单的方法,我知道的是使用XFER模式处理的图形软件包。下面的函数从削减(30,30)区出发到(100,100),从资源加载320x480的图像。适应坐标dinamically改变:

Easiest way I am aware of is to use XFer mode processing from the Graphics package. Function below cuts region starting from (30,30) till (100,100) to the 320x480 image loaded from resources. Adapt coordinates to change dinamically:

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