图像处理20210224

【Android】直播必备之YUV使用总结 —— Android常用的几种格式:NV21/NV12/YV12/YUV420P的区别...

YUV图解 (YUV444, YUV422, YUV420, YV12, NV12, NV21)

Android 图像格式ImageFormat 主要参数值说明

YuvImage知识点总结

Bitmap和byte[]的互相转换

//Bitmap转为byte[]
        Bitmap bitmap= BitmapFactory...(资源/byte[]/路径/等)
        ByteArrayOutputStream output=new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG,100,output);
        byte[] data=output.toByteArray();

//byte[]转换为Bitmap
        Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

Bitmap压缩

Android bitmap压缩方法

     /**
     * 改变bitmap尺寸大小
     *
     * @param bitmap    原始bitmap
     * @param widthNew  新的宽度
     * @param heightNew 新的高度
     * @return 改变尺寸后的bitmap
     */
    private Bitmap changeBitmapSize(Bitmap bitmap, int widthNew, int heightNew) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        float widthScale = (float) widthNew / width;
        float heightScale = (float) heightNew / height;
        Matrix matrix = new Matrix();
        matrix.postScale(widthScale, heightScale);
        return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    }

二维码相关操作

利用ZXing工具生成二维码以及解析二维码

Zxing生成、读取二维码(带logo)

zxing开源库的基本使用

工具库zxing

private static final String WHITE_COLOR = "ffffff";

/**
     * 生成二维码位图
     *
     * @param text  内容
     * @param qrLen 二维码边长
     * @return 二维码
     * @throws Exception 数据处理异常
     */
    public static Bitmap createBitmap(String text, int qrLen) throws Exception {
        if (TextUtils.isEmpty(text)) {
            return null;
        }
        Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
        //边距
        hints.put(EncodeHintType.MARGIN, 1);
        //编码格式
        hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        //纠错信息
        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, qrLen, qrLen, hints);
        //对点阵进行黑白处理
        int[] pixels = new int[qrLen * qrLen];
        for (int y = 0; y < qrLen; y++) {
            for (int x = 0; x < qrLen; x++) {
                if (bitMatrix.get(x, y)) {
                    pixels[y * qrLen + x] = 0xff000000;
                } else {
                    pixels[y * qrLen + x] = 0xffffffff;
                }
            }
        }
        Bitmap bitmap = Bitmap.createBitmap(qrLen, qrLen, Bitmap.Config.ARGB_8888);
        bitmap.setPixels(pixels, 0, qrLen, 0, 0, qrLen, qrLen);
        return bitmap;
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值