Android 中Bitmap 进行绘制编辑

private void drawBitmap(Bitmap bitmap) {

        Bitmap newBmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());

        Canvas canvas = new Canvas(newBmp);
        Paint p = new Paint();

        canvas.drawBitmap(bitmap, 0, 0, p);

        imageView.setImageBitmap(newBmp);
}
private void drawMatrixBitmap(Bitmap bitmap) {

        Bitmap newBmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());

        Canvas canvas = new Canvas(newBmp);
        Paint p = new Paint();

//        Matrix matrix = new Matrix();
//        matrix.setValues(new float[]{
//                .5f, 0, 0,
//                0, 1, 0,
//                0, 0, 1
//        });

//        Matrix matrix = new Matrix();
//        matrix.setValues(new float[] {
//                1, .5f, 0,
//                0, 1, 0,
//                0, 0, 1
//        });

        Matrix matrix = new Matrix();

//        matrix.setRotate(15);
//        matrix.setScale(1,0.5f);
//        matrix.setTranslate(1.5f,-10);

//        matrix.setScale(1.5f, 1);
//        matrix.postRotate(15,bitmap.getWidth()/2,bitmap.getHeight()/2);

        // 镜像
//        matrix.setScale(-1, 1);
//        matrix.postTranslate(bitmap.getWidth(),0);

        // 倒置
        matrix.setScale(1, -1);
        matrix.postTranslate(0, bitmap.getHeight());

        canvas.drawBitmap(bitmap, matrix, p);
        imageView.setImageBitmap(newBmp);

}
 private void matrixAndBitmap(Bitmap bitmap) {
        Matrix matrix = new Matrix();
        matrix.setRotate(15, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
        Bitmap alteredBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),
                matrix, false);
        imageView.setImageBitmap(alteredBitmap);
}
private void colorMatrixDraw(Bitmap bitmap) {

        Bitmap alteredBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
        Canvas canvas = new Canvas(alteredBitmap);
        Paint paint = new Paint();

        ColorMatrix cm = new ColorMatrix();
//        cm.set(new float[] {
//                2, 0, 0, 0, 0,
//                0, 1, 0, 0, 0,
//                0, 0, 1, 0, 0,
//                0, 0, 0, 1, 0
//        });

//        float contrast = 2;
//        cm.set(new float[] {
//                contrast, 0, 0, 0, 0,
//                0, contrast, 0, 0, 0,
//                0, 0, contrast, 0, 0,
//                0, 0, 0, 1, 0 });

//        float brightness = -25;
//        cm.set(new float[] {
//                1, 0, 0, 0, brightness,
//                0, 1, 0, 0, brightness,
//                0, 0, 1, 0, brightness,
//                0, 0, 0, 1, 0 });

//        float contrast = 2;
//        float brightness = -25;
//        cm.set(new float[] {
//                contrast, 0, 0, 0, brightness,
//                0, contrast, 0, 0, brightness,
//                0, 0, contrast, 0, brightness,
//                0, 0, 0, contrast, 0 });

        cm.setSaturation(0.5f);

        paint.setColorFilter(new ColorMatrixColorFilter(cm));

        Matrix matrix = new Matrix();
        canvas.drawBitmap(bitmap, matrix, paint);
        imageView.setImageBitmap(alteredBitmap);

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值