老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)

java二維碼制作的代碼 java二維碼制作的代碼是什么

java中怎樣用代碼生成二維碼?

參考代碼

公司主營業(yè)務(wù):成都網(wǎng)站建設(shè)、網(wǎng)站制作、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)公司是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)公司推出趙縣免費做網(wǎng)站回饋大家。

import java.io.*;

import java.util.Date;

import java.awt.*;

import java.awt.image.*;

import javax.imageio.*;

public class QRCodeEncoderTest

{

/** Creates a new instance of QRCodeEncoderTest */

public QRCodeEncoderTest()

{

}

public static void create_image(String sms_info)throws Exception{

try{

qrcode testQrcode =new qrcode();

testQrcode.setQrcodeErrorCorrect('M');

testQrcode.setQrcodeEncodeMode('B');

testQrcode.setQrcodeVersion(7);

String testString = sms_info;

byte[] d = testString.getBytes("gbk");

System.out.println(d.length);

//BufferedImage bi = new BufferedImage(98, 98, BufferedImage.TYPE_INT_RGB);

BufferedImage bi = new BufferedImage(98, 98, BufferedImage.TYPE_BYTE_BINARY);

Graphics2D g = bi.createGraphics();

g.setBackground(Color.WHITE);

g.clearRect(0, 0, 98, 98);

g.setColor(Color.BLACK);

// 限制最大字節(jié)數(shù)為120

if (d.length0 d.length 120){

boolean[][] s = testQrcode.calQrcode(d);

for (int i=0;is.length;i++){

for (int j=0;js.length;j++){

if (s[j][i]) {

g.fillRect(j*2+3,i*2+3,2,2);

}

}

}

}

g.dispose();

bi.flush();

File f = new File("D:\\QRCodeTest\\"+sms_info+".jpg");

if(!f.exists()){

f.createNewFile();

}

//創(chuàng)建圖片

ImageIO.write(bi, "jpg", f);

} // end try

catch (Exception e) {

e.printStackTrace();

} // end catch

}

public static void main(String[] args) throws Exception {

System.out.println(new Date());

for(int i =1; i 100000; i ++){

QRCodeEncoderTest.create_image(i+"");

}

System.out.println(new Date());

} // end main

}

如何用java生成二維碼

package?common;

import?java.awt.Color;

import?java.awt.Graphics2D;

import?java.awt.Image;

import?java.awt.image.BufferedImage;

import?java.io.File;

import?java.io.IOException;

import?java.util.HashMap;

import?java.util.Map;

import?javax.imageio.ImageIO;

import?jp.sourceforge.qrcode.QRCodeDecoder;

import?jp.sourceforge.qrcode.exception.DecodingFailedException;

import?com.google.zxing.BarcodeFormat;

import?com.google.zxing.Binarizer;

import?com.google.zxing.BinaryBitmap;

import?com.google.zxing.EncodeHintType;

import?com.google.zxing.LuminanceSource;

import?com.google.zxing.MultiFormatReader;

import?com.google.zxing.MultiFormatWriter;

import?com.google.zxing.NotFoundException;

import?com.google.zxing.WriterException;

import?com.google.zxing.common.BitMatrix;

import?com.google.zxing.common.HybridBinarizer;

import?com.swetake.util.Qrcode;

/**

*?二維碼生成工具類

*?@author?Cloud

*?@data???2016-12-15

*?QRCode

*/

public?class?QRCodeUtil?{

//二維碼顏色

private?static?final?int?BLACK?=?0xFF000000;

//二維碼顏色

private?static?final?int?WHITE?=?0xFFFFFFFF;

/**

*?span?style="font-size:18px;font-weight:blod;"ZXing?方式生成二維碼/span

*?@param?text????a?href="javascript:void();"二維碼內(nèi)容/a

*?@param?width????二維碼寬

*?@param?height????二維碼高

*?@param?outPutPath????二維碼生成保存路徑

*?@param?imageType????????二維碼生成格式

*/

public?static?void?zxingCodeCreate(String?text,?int?width,?int?height,?String?outPutPath,?String?imageType){

MapEncodeHintType,?String?his?=?new?HashMapEncodeHintType,?String();

//設(shè)置編碼字符集

his.put(EncodeHintType.CHARACTER_SET,?"utf-8");

try?{

//1、生成二維碼

BitMatrix?encode?=?new?MultiFormatWriter().encode(text,?BarcodeFormat.QR_CODE,?width,?height,?his);

//2、獲取二維碼寬高

int?codeWidth?=?encode.getWidth();

int?codeHeight?=?encode.getHeight();

//3、將二維碼放入緩沖流

BufferedImage?image?=?new?BufferedImage(codeWidth,?codeHeight,?BufferedImage.TYPE_INT_RGB);

for?(int?i?=?0;?i??codeWidth;?i++)?{

for?(int?j?=?0;?j??codeHeight;?j++)?{

//4、循環(huán)將二維碼內(nèi)容定入圖片

image.setRGB(i,?j,?encode.get(i,?j)???BLACK?:?WHITE);

}

}

File?outPutImage?=?new?File(outPutPath);

//如果圖片不存在創(chuàng)建圖片

if(!outPutImage.exists())

outPutImage.createNewFile();

//5、將二維碼寫入圖片

ImageIO.write(image,?imageType,?outPutImage);

}?catch?(WriterException?e)?{

e.printStackTrace();

System.out.println("二維碼生成失敗");

}?catch?(IOException?e)?{

e.printStackTrace();

System.out.println("生成二維碼圖片失敗");

}

}

/**

*?span?style="font-size:18px;font-weight:blod;"二維碼解析/span

*?@param?analyzePath????二維碼路徑

*?@return

*?@throws?IOException

*/

@SuppressWarnings({?"rawtypes",?"unchecked"?})

public?static?Object?zxingCodeAnalyze(String?analyzePath)?throws?Exception{

MultiFormatReader?formatReader?=?new?MultiFormatReader();

Object?result?=?null;

try?{

File?file?=?new?File(analyzePath);

if?(!file.exists())

{

return?"二維碼不存在";

}

BufferedImage?image?=?ImageIO.read(file);

LuminanceSource?source?=?new?LuminanceSourceUtil(image);

Binarizer?binarizer?=?new?HybridBinarizer(source);??

BinaryBitmap?binaryBitmap?=?new?BinaryBitmap(binarizer);

Map?hints?=?new?HashMap();

hints.put(EncodeHintType.CHARACTER_SET,?"UTF-8");

result?=?formatReader.decode(binaryBitmap,?hints);

}?catch?(NotFoundException?e)?{

e.printStackTrace();

}??

return?result;

}

/**

*?span?style="font-size:18px;font-weight:blod;"QRCode?方式生成二維碼/span

*?@param?content????二維碼內(nèi)容

*?@param?imgPath????二維碼生成路徑

*?@param?version????二維碼版本

*?@param?isFlag????是否生成Logo圖片????為NULL不生成

*/

public?static?void?QRCodeCreate(String?content,?String?imgPath,?int?version,?String?logoPath){

try?{??

Qrcode?qrcodeHandler?=?new?Qrcode();??

//設(shè)置二維碼排錯率,可選L(7%)?M(15%)?Q(25%)?H(30%),排錯率越高可存儲的信息越少,但對二維碼清晰度的要求越小????

qrcodeHandler.setQrcodeErrorCorrect('M');??

//N代表數(shù)字,A代表字符a-Z,B代表其他字符??

qrcodeHandler.setQrcodeEncodeMode('B');??

//版本1為21*21矩陣,版本每增1,二維碼的兩個邊長都增4;所以版本7為45*45的矩陣;最高版本為是40,是177*177的矩陣??

qrcodeHandler.setQrcodeVersion(version);

//根據(jù)版本計算尺寸

int?imgSize?=?67?+?12?*?(version?-?1)?;??

byte[]?contentBytes?=?content.getBytes("gb2312");??

BufferedImage?bufImg?=?new?BufferedImage(imgSize?,?imgSize?,BufferedImage.TYPE_INT_RGB);??

Graphics2D?gs?=?bufImg.createGraphics();??

gs.setBackground(Color.WHITE);??

gs.clearRect(0,?0,?imgSize?,?imgSize);??

//?設(shè)定圖像顏色??BLACK

gs.setColor(Color.BLACK);

//?設(shè)置偏移量?不設(shè)置可能導(dǎo)致解析出錯??

int?pixoff?=?2;

//?輸出內(nèi)容??二維碼??

if?(contentBytes.length??0??contentBytes.length??130)?{

boolean[][]?codeOut?=?qrcodeHandler.calQrcode(contentBytes);

for?(int?i?=?0;?i??codeOut.length;?i++)?{

for?(int?j?=?0;?j??codeOut.length;?j++)?{

if?(codeOut[j][i])?{??

gs.fillRect(j?*?3?+?pixoff,?i?*?3?+?pixoff,?3,?3);

}??

}??

}??

}?else?{??

System.err.println("QRCode?content?bytes?length?=?"?+?contentBytes.length?+?"?not?in?[?0,130?].?");??

}

/*?判斷是否需要添加logo圖片?*/

if(logoPath?!=?null){

File?icon?=?new?File(logoPath);

if(icon.exists()){

int?width_4?=?imgSize?/?4;

int?width_8?=?width_4?/?2;

int?height_4?=?imgSize?/?4;

int?height_8?=?height_4?/?2;

Image?img?=?ImageIO.read(icon);

gs.drawImage(img,?width_4?+?width_8,?height_4?+?height_8,width_4,height_4,?null);

gs.dispose();

bufImg.flush();

}else{

System.out.println("Error:?login圖片還在在!");

}

}

gs.dispose();

bufImg.flush();

//創(chuàng)建二維碼文件

File?imgFile?=?new?File(imgPath);

if(!imgFile.exists())

imgFile.createNewFile();

//根據(jù)生成圖片獲取圖片

String?imgType?=?imgPath.substring(imgPath.lastIndexOf(".")?+?1,?imgPath.length());

//?生成二維碼QRCode圖片??

ImageIO.write(bufImg,?imgType,?imgFile);??

}?catch?(Exception?e)?{??

e.printStackTrace();??

}

}

/**

*?span?style="font-size:18px;font-weight:blod;"QRCode二維碼解析/span

*?@param?codePath????二維碼路徑

*?@return????解析結(jié)果

*/

public?static?String?QRCodeAnalyze(String?codePath)?{

File?imageFile?=?new?File(codePath);

BufferedImage?bufImg?=?null;??

String?decodedData?=?null;??

try?{

if(!imageFile.exists())

return?"二維碼不存在";

bufImg?=?ImageIO.read(imageFile);

QRCodeDecoder?decoder?=?new?QRCodeDecoder();??

decodedData?=?new?String(decoder.decode(new?ImageUtil(bufImg)),?"gb2312");??

}?catch?(IOException?e)?{??

System.out.println("Error:?"?+?e.getMessage());??

e.printStackTrace();??

}?catch?(DecodingFailedException?dfe)?{??

System.out.println("Error:?"?+?dfe.getMessage());??

dfe.printStackTrace();??

}

return?decodedData;

}

}

3、最后貼測試代碼:

package?test;

import?java.awt.image.BufferedImage;

import?java.io.InputStream;

import?java.net.URL;

import?javax.imageio.ImageIO;

import?common.ImageUtil;

import?common.QRCodeUtil;

import?jp.sourceforge.qrcode.QRCodeDecoder;

/**

*?二維碼生成測試類

*?@author?Cloud

*?@data???2016-11-21

*?QRCodeTest

*/

public?class?QRCodeTest?{

public?static?void?main(String[]?args)?throws?Exception?{

/**

*????QRcode?二維碼生成測試

*????QRCodeUtil.QRCodeCreate("",?"E://qrcode.jpg",?15,?"E://icon.png");

*/

/**

*?????QRcode?二維碼解析測試

*????String?qrcodeAnalyze?=?QRCodeUtil.QRCodeAnalyze("E://qrcode.jpg");

*/

/**

*?ZXingCode?二維碼生成測試

*?QRCodeUtil.zxingCodeCreate("",?300,?300,?"E://zxingcode.jpg",?"jpg");

*/

/**

*?ZxingCode?二維碼解析

*????String?zxingAnalyze?=??QRCodeUtil.zxingCodeAnalyze("E://zxingcode.jpg").toString();

*/

System.out.println("success");

}

}

如何使用java開發(fā)二維碼代碼

1: 使用SwetakeQRCode在Java項目中生成二維碼

下載地址

或著

這個是日本人寫的,生成的是我們常見的方形的二維碼

可以用中文

如:5677777ghjjjjj

2: 使用BarCode4j生成條形碼和二維碼

BarCode4j網(wǎng)址:

barcode4j是使用datamatrix的二維碼生成算法,為支持qr的算法

datamatrix是歐美的標(biāo)準(zhǔn),qr為日本的標(biāo)準(zhǔn),

barcode4j一般生成出來是長方形的

如:88777alec000yan

這個博客這方面說的挺清楚的:

3:zxing

zxing 這個是google的

下載地址

Java代碼:

import java.io.File;

import java.util.Hashtable;

import com.google.zxing.BarcodeFormat;

import com.google.zxing.EncodeHintType;

import com.google.zxing.MultiFormatWriter;

import com.google.zxing.client.j2se.MatrixToImageWriter;

import com.google.zxing.common.BitMatrix;

import com.google.zxing.qrcode.QRCodeWriter;

public class QRCodeEvents {

public static void main(String []args)throws Exception{

String text = "你好";

int width = 100;

int height = 100;

String format = "png";

Hashtable hints= new Hashtable();

hints.put(EncodeHintType.CHARACTER_SET, "utf-8");

BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height,hints);

File outputFile = new File("new.png");

MatrixToImageWriter.writeToFile(bitMatrix, format, outputFile);

}

}

4:google chart api就有實現(xiàn)二維碼的方法

利用這個api,使用google appengine進行實現(xiàn)。

5:JS生成二維碼

使用jQuery-qrcode生成二維碼

先簡單說一下jquery-qrcode,這個開源的三方庫(可以從 獲取),

qrcode.js 是實現(xiàn)二維碼數(shù)據(jù)計算的核心類,

jquery.qrcode.js 是把它用jquery方式封裝起來的,用它來實現(xiàn)圖形渲染,其實就是畫圖(支持canvas和table兩種方式)

支持的功能主要有:

Js代碼:

text : "" //設(shè)置二維碼內(nèi)容

Js代碼:

render : "canvas",//設(shè)置渲染方式

width : 256, //設(shè)置寬度

height : 256, //設(shè)置高度

typeNumber : -1, //計算模式

correctLevel : QRErrorCorrectLevel.H,//糾錯等級

background : "#ffffff",//背景顏色

foreground : "#000000" //前景顏色

使用方式非常簡單

Js代碼:

jQuery('#output').qrcode({width:200,height:200,correctLevel:0,text:content});

經(jīng)過簡單實踐,

使用canvas方式渲染性能還是非常不錯的,但是如果用table方式,性能不太理想,特別是IE9以下的瀏覽器,所以需要自行優(yōu)化一下渲染table的方式,這里就不細述了。

其實上面的js有一個小小的缺點,就是默認不支持中文。

這跟js的機制有關(guān)系,jquery-qrcode這個庫是采用 charCodeAt() 這個方式進行編碼轉(zhuǎn)換的,

而這個方法默認會獲取它的 Unicode 編碼,一般的解碼器都是采用UTF-8, ISO-8859-1等方式,

英文是沒有問題,如果是中文,一般情況下Unicode是UTF-16實現(xiàn),長度2位,而UTF-8編碼是3位,這樣二維碼的編解碼就不匹配了。

解決方式當(dāng)然是,在二維碼編碼前把字符串轉(zhuǎn)換成UTF-8,具體代碼如下:

function utf16to8(str) {

var out, i, len, c;

out = "";

len = str.length;

for(i = 0; i len; i++) {

c = str.charCodeAt(i);

if ((c = 0x0001) (c = 0x007F)) {

out += str.charAt(i);

} else if (c 0x07FF) {

out += String.fromCharCode(0xE0 | ((c 12) 0x0F));

out += String.fromCharCode(0x80 | ((c 6) 0x3F));

out += String.fromCharCode(0x80 | ((c 0) 0x3F));

} else {

out += String.fromCharCode(0xC0 | ((c 6) 0x1F));

out += String.fromCharCode(0x80 | ((c 0) 0x3F));

}

}

return out;

}


網(wǎng)站標(biāo)題:java二維碼制作的代碼 java二維碼制作的代碼是什么
標(biāo)題路徑:http://www.xueling.net.cn/article/dopopjs.html

其他資訊

在線咨詢
服務(wù)熱線
服務(wù)熱線:028-86922220
TOP
主站蜘蛛池模板: 国产精品美女久久久浪潮av | 卫生间被教官做好爽HH视频 | 国内精品久久久久久久影视蜜臀 | 无码精品一区二区三区免费视频 | 高清录播系统在线录播 | 999亚洲精品无码久久久久 | 成人精品天堂一区二区三区 | 动漫一品二品精区在线 | 春水堂av导航 | 91精品国产高清久久久久久久久 | 人人澡人人草 | 亚洲天堂男人的天堂 | 国产精品国产三级国产aⅴ无密码 | 午夜精品久久久99热使用方法 | 国产乱操 | 国产亚洲高清视频你懂 | 伊人黄色片一 | 嘿咻嘿咻在线观看 | 惊爆摩天楼在线观看 | 久久久久久久久一 | 高清精品福利私拍国产写真 | 亚洲一区二区三区在线网站 | 777米奇影视第四色 青青青在线视频观看 | 国产精品a久久久久 | 国产91亚洲精品 | 中文字幕人成无码人妻 | a4yy午夜福利网在线观看 | 人妻熟女一二三区夜夜爱 | 日本欧美国产 | 六月成人网 | 久久综合狠狠综合久久激情 | 欧美日韩视频在线播放 | 在教室伦流澡到高潮H强圩动漫 | 91在线91拍拍在线91 | 无码精品人妻一区二区三区98 | 国产精品黄桃 | 少妇又紧又粗又爽的视频 | 国产精品无码翘臀在线看 | 国产精品白浆无码流出 | 成人深夜视频在线观看 | 国产在线观看高清视频黄网 |