<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);
               
                // 設定QR Code 編碼內容
                String testString = "";
                testString = testString+"JavaWorld .\n";
                testString = testString+"中文Java討論網站\n";
                testString = testString+"http://www.javaworld.com\n";
               
                // getBytes
                byte[] d = testString.getBytes("Big5");
               
                // 設定圖檔寬度 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);
               
                // 設定字型顏色 => BLACK
                g.setColor(Color.BLACK);
               
                // 轉出 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();
               
                // 設定 產生檔案路徑
                String FilePath="D:\\TestQRCode.jpg";
                File f = new File(FilePath);
               
                // 產生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();

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

    // 設定 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 閱讀(543) 評論(0)  編輯  收藏 所屬分類: java
    主站蜘蛛池模板: 亚洲Av综合色区无码专区桃色| 中文字幕在线亚洲精品 | 久久久久亚洲AV综合波多野结衣| 亚洲丶国产丶欧美一区二区三区| 成年丰满熟妇午夜免费视频| 亚洲男人天堂2022| 免费观看理论片毛片| 亚洲AV综合色区无码一二三区| 日韩毛片免费在线观看| 精品国产亚洲第一区二区三区| 波多野结衣视频在线免费观看| 牛牛在线精品观看免费正| 伊人婷婷综合缴情亚洲五月| 四虎影视无码永久免费| 亚洲国产日韩一区高清在线| 精品香蕉在线观看免费| 亚洲午夜成人精品无码色欲| 国产免费牲交视频| 中国一级毛片视频免费看| 亚洲AV福利天堂一区二区三| 国产在线jyzzjyzz免费麻豆 | 鲁死你资源站亚洲av| 日韩电影免费在线| 精品无码国产污污污免费网站国产| 国产日产亚洲系列| 亚洲综合免费视频| 国产精品亚洲精品久久精品| 亚洲乱码日产一区三区| 亚洲大片免费观看| 亚洲乱码日产精品一二三| 亚洲视频一区二区| 亚洲成人免费网址| 一个人免费观看日本www视频 | 全免费a级毛片免费看无码| jizz在线免费观看| ww亚洲ww在线观看国产| 亚洲成人影院在线观看| 蜜臀AV免费一区二区三区| 免费在线观看自拍性爱视频| 亚洲AV福利天堂一区二区三| 在线观看免费亚洲|