第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何去除 zxing 生成的 QRCode 的邊距?

如何去除 zxing 生成的 QRCode 的邊距?

泛舟湖上清波郎朗 2022-05-21 17:09:57
我正在使用 com.google.zxing 版本 3.3.2 使用 jasper 報告生成 QRCode。生成的二維碼有空格和邊距。我怎樣才能避免這些空間。我找到了添加 EncodeHintType.MARGIN, -1 的解決方案,但是如何在 jasper 報告中的圖像表達式中添加它。下面是我現(xiàn)在使用的圖像表達式。com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(new com.google.zxing.qrcode.QRCodeWriter().encode(    $F{Code},com.google.zxing.BarcodeFormat.QR_CODE, 300, 300))
查看完整描述

1 回答

?
猛跑小豬

TA貢獻1858條經(jīng)驗 獲得超8個贊

添加 EncodeHintType.MARGIN是正確的但是你需要輸入0(否則會拋出錯誤)


要添加它,您可以使用QRCodeWriter的第二個構(gòu)造函數(shù)


public BitMatrix encode(String contents,BarcodeFormat format,

                        int width,int height,Map<EncodeHintType,?> hints) 

                        throws WriterException 

這意味著您需要傳遞一個使用鍵和值初始化的 Map。創(chuàng)建和初始化地圖的一種方法是使用Guava,它是ImmutableMap


com.google.common.collect.ImmutableMap.of(com.google.zxing.EncodeHintType.MARGIN,0)

因此,結(jié)果表達式將是


com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(

    new com.google.zxing.qrcode.QRCodeWriter().encode(

    $F{Code},com.google.zxing.BarcodeFormat.QR_CODE, 300, 300,

    com.google.common.collect.ImmutableMap.of(com.google.zxing.EncodeHintType.MARGIN,0)))

示例(我放了一個邊框來展示邊距 0)

jrxml


<?xml version="1.0" encoding="UTF-8"?>

<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="QRCode" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ee443473-56d0-44df-b5d4-ac3fe82fd9bc">

    <queryString>

        <![CDATA[]]>

    </queryString>

    <title>

        <band height="200" splitType="Stretch">

            <image>

                <reportElement x="0" y="0" width="200" height="200" uuid="9236a226-c581-4d35-88d3-c65181090d03"/>

                <box>

                    <pen lineWidth="0.25"/>

                    <topPen lineWidth="0.25" lineStyle="Solid" lineColor="#000000"/>

                    <leftPen lineWidth="0.25" lineStyle="Solid" lineColor="#000000"/>

                    <bottomPen lineWidth="0.25" lineStyle="Solid" lineColor="#000000"/>

                    <rightPen lineWidth="0.25" lineStyle="Solid" lineColor="#000000"/>

                </box>

                <imageExpression><![CDATA[com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(

new com.google.zxing.qrcode.QRCodeWriter().encode(

    "Hello world",com.google.zxing.BarcodeFormat.QR_CODE, 300, 300,com.google.common.collect.ImmutableMap.of(com.google.zxing.EncodeHintType.MARGIN,0)))]]></imageExpression>

            </image>

        </band>

    </title>

</jasperReport>

結(jié)果

http://img1.sycdn.imooc.com//6288ac800001748704230282.jpg

查看完整回答
反對 回復(fù) 2022-05-21
  • 1 回答
  • 0 關(guān)注
  • 598 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號