Android图片裁剪

来源:互联网 发布:阿里云在线客服 编辑:程序博客网 时间:2024/05/18 10:17


在进行扩大的时候要判断坐标以及宽高的控制,防止出现bug


/** * 裁剪照片 * 根据传入的照片以及要裁剪的坐标,以及裁剪的宽高来裁剪 * 裁剪时把图片宽高扩大20 * 在裁剪的坐标点-10 * 在宽高的基础上+10 * * @param bitmap * @return */public static Bitmap getcreateBitmap(Bitmap bitmap, int x, int y, int width, int height) {    int x1;//最终x坐标    if (x < 10) {        x1 = x;    } else {        x1 = x - 10;    }    int y1;//最终y坐标    if (y < 10) {        y1 = y;    } else {        y1 = y - 10;    }    int width1;//最终图片宽    int pwidth = bitmap.getWidth();    int tempwidth = x + width + 20;//判断总宽有没有超过源照片的的宽    if (tempwidth > pwidth) {        width1 = width;    } else {        width1 = width + 20;    }    int height1;//最终图片高    int pheight = bitmap.getHeight();    int tempheight = y + height + 20;//判断总高有没有超过源照片的的高    if (tempheight > pheight) {        height1 = height;    } else {        height1 = height + 20;    }    Bitmap b = Bitmap.createBitmap(bitmap, x1, y1, width1, height1);    return b;}


原创粉丝点击