剪切位图的一部分 [英] cut the portion of bitmap

查看:58
本文介绍了剪切位图的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
如何在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..

推荐答案

我所知道的最简单的方法是使用 Graphics 包中的 XFer 模式处理.下面的函数将区域从 (30,30) 到 (100,100) 剪切到从资源加载的 320x480 图像.调整坐标动态变化:

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 dynamically:

private Bitmap cropBitmap1() {
    Bitmap bmp2 = BitmapFactory.decodeResource(this.getResources(), R.drawable.image1); 
    Bitmap bmOverlay = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);

    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));

    Canvas canvas = new Canvas(bmOverlay); 
    canvas.drawBitmap(bmp2, 0, 0, null); 
    canvas.drawRect(30, 30, 100, 100, paint);

    return bmOverlay;
}

这篇关于剪切位图的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆