日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

关于Zxing生成DM二维码变形问题总结

發布時間:2024/8/1 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于Zxing生成DM二维码变形问题总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用Zxing生成DM碼不是正方形的問題

在hints中增加
hints.put(EncodeHintType.DATA_MATRIX_SHAPE, SymbolShapeHint.FORCE_SQUARE);//設置樣式:不設置,正方形,矩形

SymbolShapeHint.FORCE_NONE 默認
SymbolShapeHint.FORCE_SQUARE 正方形
SymbolShapeHint.FORCE_RECTANGLE 矩形

/*** @param content 二維碼內容* @param width 二維碼寬度* @param height 二維碼高度* @param charset 字符編碼* @param barcodeFormat 二維碼類型QR、DM、條形碼* @param errorCorrectionLevel 容錯級別* @param margin 邊距* @param color 二維碼顏色 16進制 例如:#ff000000* @param colorBg 背景色 16進制 例如:#ffffffff* @return*/public static Bitmap createImage(String content, int width, int height, String charset,BarcodeFormat barcodeFormat,ErrorCorrectionLevel errorCorrectionLevel,int margin, int color, int colorBg) {try {//判斷URL合法性if (content == null || "".equals(content) || content.length() < 1) {return null;}Hashtable<EncodeHintType, Object> hints = new Hashtable<>();hints.put(EncodeHintType.CHARACTER_SET, charset);//編碼格式hints.put(EncodeHintType.ERROR_CORRECTION, errorCorrectionLevel);//容錯類型hints.put(EncodeHintType.MARGIN, margin);//邊距hints.put(EncodeHintType.DATA_MATRIX_SHAPE, SymbolShapeHint.FORCE_SQUARE);//設置樣式:不設置,正方形,矩形//圖像數據轉換,使用了矩陣轉換BitMatrix bitMatrix = new MultiFormatWriter().encode(content, barcodeFormat, width, height, hints);int[] pixels = new int[width * height];//下面這里按照二維碼的算法,逐個生成二維碼的圖片,//兩個for循環是圖片橫列掃描的結果for (int y = 0; y < height; y++) {for (int x = 0; x < width; x++) {if (bitMatrix.get(x, y)) {pixels[y * width + x] = color;} else {pixels[y * height + x] = colorBg;}}}//生成二維碼圖片的格式,使用ARGB_8888Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);bitmap.setPixels(pixels, 0, width, 0, 0, width, height);return bitmap;} catch (WriterException e) {e.printStackTrace();return null;}}

調用方法

createImage(content, width, height, "utf-8",BarcodeFormat.DATA_MATRIX, errorCorrectionLevel, margin, 0XFF000000, 0XFFFFFFFF);

總結

以上是生活随笔為你收集整理的关于Zxing生成DM二维码变形问题总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。