<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 22,comments - 35,trackbacks - 0
    QR Code 編碼

    /*********************************************************
    *
    * Created on 2007年3月1日
    *
    * Program : QRCodeEncoderTest.java
    * @author : ryanpai
    * Java平臺 : J2SDK 1.4.9
    * OS : XP
    * 1. 下載使用 (http://www.swetake.com/qr/ ) qrcode.jar
    *     => 建議改為qr_encode.jar
    *     (因為跟SourceForge QR Code Decode Library 之 qrcode.jar 同名)
    * 2. 將上述下載的 jar 增加至classpath
    *
    ********************************************************/


    import com.swetake.util.Qrcode;
    import java.io.*;

    import java.awt.*;
    import java.awt.image.*;
    import javax.imageio.*;

    /******************************************
    *
    * @author  Ryan Pai
    *
    ******************************************/


    public class QRCodeEncoderTest {
       
        /** Creates a new instance of QRCodeEncoderTest */
        public QRCodeEncoderTest() {
        }
       
        /**
         * @param args the command line arguments
         */

       
        public static void main(String[] args) {
           
            try{
               
                // TODO code application logic here
               
                // Constructor Qrcode Object
                com.swetake.util.Qrcode testQrcode
                      = new com.swetake.util.Qrcode();
                testQrcode.setQrcodeErrorCorrect('M');
                testQrcode.setQrcodeEncodeMode('B');
                testQrcode.setQrcodeVersion(7);
               
                // 設(shè)定QR Code 編碼內(nèi)容
                String testString = "";
                testString = testString+"JavaWorld .\n";
                testString = testString+"中文Java討論網(wǎng)站\n";
                testString = testString+"http://www.javaworld.com\n";
               
                // getBytes
                byte[] d = testString.getBytes("Big5");
               
                // 設(shè)定圖檔寬度 140*140
                BufferedImage bi
                = new BufferedImage(140, 140, BufferedImage.TYPE_INT_RGB);
               
                // createGraphics
                Graphics2D g = bi.createGraphics();
               
                // set background
                g.setBackground(Color.WHITE);
                g.clearRect(0, 0, 140, 140);
               
                // 設(shè)定字型顏色 => BLACK
                g.setColor(Color.BLACK);
               
                // 轉(zhuǎn)出 Bytes
                if (d.length>0 && d.length <120){
                    boolean[][] s = testQrcode.calQrcode(d);
                    for (int i=0;i<s.length;i++){
                        for (int j=0;j<s.length;j++){
                            if (s[j][i]) {
                                g.fillRect(j*3+2,i*3+2,3,3);
                            }
                        }
                    }
                }
               
                g.dispose();
                bi.flush();
               
                // 設(shè)定 產(chǎn)生檔案路徑
                String FilePath="D:\\TestQRCode.jpg";
                File f = new File(FilePath);
               
                // 產(chǎn)生TestQRCode JPG File
                ImageIO.write(bi, "jpg", f);
               
            } // end try
            catch (Exception e) {
                e.printStackTrace();
            } // end catch
           
    QR Code 解碼

    /*********************************************************
    *
    * Created on 2007年3月1日
    *
    * Program : QRCodeDecoderTest.java
    * @author : ryanpai
    * Java平臺 : J2SDK 1.4.9
    * OS : XP
    * 1. 下載使用 (http://sourceforge.jp/projects/qrcode/ ) qrcode.jar
    * => (SourceForge Open Source QR Code Decode Library)
    * 2. 修改官方 Sample => QRCodeDecoderCUIExample.java
    * 3. 將上述下載的 jar 增加至classpath
    *
    ********************************************************/


    import jp.sourceforge.qrcode.codec.QRCodeDecoder;
    import jp.sourceforge.qrcode.codec.data.QRCodeImage;
    import jp.sourceforge.qrcode.codec.exception.DecodingFailedException;
    import jp.sourceforge.qrcode.codec.exception.InvalidVersionInfoException;

    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
    import java.io.File;
    import java.io.IOException;

    /******************************************
    *
    * @author RYANPAI
    *
    ******************************************/


    public class QRCodeDecoderTest {

    /** Creates a new instance of QRCodeDecoderTest */
    public QRCodeDecoderTest() {
    }

    /**
    * @param args the command line arguments
    */

    public static void main(String[] args) {

    // TODO code application logic here
    QRCodeDecoder decoder = new QRCodeDecoder();

    // 設(shè)定讀取QR Code圖檔路徑
    File imageFile = new File("D:\\TestQRCode.jpg");

    // 設(shè)定 BufferedImage
    BufferedImage image = null;

    try {
    image = ImageIO.read(imageFile);
    } catch (IOException e) {
    System.out.println("Error: "+ e.getMessage());
    }
    try {
    String decodedData
    = new String(decoder.decode(new J2SEImage(image)));
    System.out.println(decodedData);
    } catch (DecodingFailedException dfe) {
    System.out.println("Error: " + dfe.getMessage());
    }


    }
    }

    class J2SEImage implements QRCodeImage {
    BufferedImage image;

    public J2SEImage(BufferedImage image) {
    this.image = image;
    }

    public int getWidth() {
    return image.getWidth();
    }

    public int getHeight() {
    return image.getHeight();
    }

    public int getPixel(int x, int y) {
    return image.getRGB(x, y);
    }

    }

    } // end main


    }
    posted on 2009-06-29 15:59 kelven 閱讀(552) 評論(0)  編輯  收藏 所屬分類: java
    主站蜘蛛池模板: 免费国产真实迷j在线观看| 国产激情免费视频在线观看| 2021免费日韩视频网| 亚洲A∨无码无在线观看| 中文在线日本免费永久18近| 亚洲性久久久影院| 一区二区三区免费在线观看| 亚洲国产电影av在线网址| 免费看又黄又爽又猛的视频软件| 日本不卡免费新一二三区| 小说区亚洲自拍另类| 亚洲欧洲日本在线| 国产免费福利体检区久久| 亚洲国产综合无码一区| 一区二区三区观看免费中文视频在线播放 | 亚洲Av永久无码精品三区在线| 东北美女野外bbwbbw免费| 久久久久亚洲av无码尤物| 亚洲综合免费视频| 亚洲人成色在线观看| 日韩精品亚洲专区在线观看| 91免费在线视频| 亚洲综合色一区二区三区小说| 日韩国产免费一区二区三区| 亚洲AV无码一区二区三区牲色| 亚洲日本在线观看视频| 无码一区二区三区免费| 亚洲已满18点击进入在线观看| 免费一级毛片免费播放| 在线观看免费无码专区| 国产成人亚洲综合一区| 亚洲一级片免费看| 2022久久国产精品免费热麻豆| 在线观看亚洲AV每日更新无码| 亚洲国产精品国产自在在线 | 最近2022中文字幕免费视频| 亚洲色大成网站www尤物| 国内精品久久久久久久亚洲| 免费精品国产自产拍在| 黄色毛片免费在线观看| 久久精品国产亚洲AV电影|