QR코드 생성기 및 LOG
Property_Qrcode.java
package leo;
import java.io.Serializable;
public class Property_Qrcode implements Serializable {
private static final long serialVersionUID = 1L;
//
private String content;
//
private String qrcodePath;
//LOG
private String logoPath;
//
private int width;
//
private int height;
// LOG
private boolean isFiag;
//
private String format;
//
private char qrcodeErrorCorrect;
//
private char qrcodeEncodeModel;
//
private int version;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getQrcodePath() {
return qrcodePath;
}
public void setQrcodePath(String qrcodePath) {
this.qrcodePath = qrcodePath;
}
public String getLogoPath() {
return logoPath;
}
public void setLogoPath(String logoPath) {
this.logoPath = logoPath;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public boolean isFiag() {
return isFiag;
}
public void setFiag(boolean isFiag) {
this.isFiag = isFiag;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
public char getQrcodeErrorCorrect() {
return qrcodeErrorCorrect;
}
public void setQrcodeErrorCorrect(char qrcodeErrorCorrect) {
this.qrcodeErrorCorrect = qrcodeErrorCorrect;
}
public char getQrcodeEncodeModel() {
return qrcodeEncodeModel;
}
public void setQrcodeEncodeModel(char qrcodeEncodeModel) {
this.qrcodeEncodeModel = qrcodeEncodeModel;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
QrCode.java
package leo;
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.text.SimpleDateFormat;
import java.util.Date;
import javax.imageio.ImageIO;
import com.swetake.util.Qrcode;
public class QrCode {
public static void main(String[] args) {
String content = " LOVe ";
Property_Qrcode qrcode = new Property_Qrcode();
qrcode.setContent(content);
//
qrcode.setQrcodePath("F:/new_example/QrcodeImage/");
//LOG
qrcode.setLogoPath("F:/new_example/QrcodeImage/DSC05666.jpg");
qrcode.setFormat("png");
// LOG true log
qrcode.setFiag(true);
qrcode.setQrcodeEncodeModel('M');
qrcode.setWidth(140);
qrcode.setHeight(140);
qrcode.setVersion(7);
qrcode.setQrcodeEncodeModel('B');
QrCode.createQRCode(qrcode);
System.out.println("encode qrcode success!");
}
private static void createQRCode(Property_Qrcode qrcode) {
// TODO Auto-generated method stub
try {
Qrcode handler = new Qrcode();
handler.setQrcodeEncodeMode(qrcode.getQrcodeEncodeModel());
handler.setQrcodeErrorCorrect(qrcode.getQrcodeErrorCorrect());
handler.setQrcodeVersion(qrcode.getVersion());
byte[] contentBytes = qrcode.getContent().getBytes("gb2312");
int width = qrcode.getWidth();
int height = qrcode.getHeight();
BufferedImage bufImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D gs = bufImg.createGraphics();
gs.setBackground(Color.WHITE);
gs.clearRect(0, 0, width, height);
gs.setColor(Color.BLACK);
int pixoff = 3;
System.out.println("contentBytes.length = "+contentBytes.length );
if (contentBytes.length > 0 && contentBytes.length < width ) {
boolean[][] codeOut = handler.calQrcode(contentBytes);
for (int i = 0; i < codeOut.length; i++) {
for (int j = 0; j < codeOut.length; j++) {
if (codeOut[i][j]) {
gs.fillRect(j * 3 + pixoff, i * 3 + pixoff, 3, 3);
}
}
}
} else {
System.out.println("QRCode content byte length "
+ contentBytes.length + " not in 200");
}
if(qrcode.isFiag()){
int width_4 = width / 4;
int width_8 = width_4 /2;
int height_4 = height /4;
int height_8 = height_4 / 2;
Image img = ImageIO.read(new File(qrcode.getLogoPath()));
gs.drawImage(img, width_4 + width_8, height_4 + height_8,width_4,height_4,null);
gs.dispose();
bufImg.flush();
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String fileName = sdf.format(new Date())+"."+qrcode.getFormat();
System.out.println(fileName);
String url = qrcode.getQrcodePath() + fileName;
File imgFile = new File(url);
if(!imgFile.exists()){
imgFile.mkdirs();
}
ImageIO.write(bufImg, qrcode.getFormat(), imgFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
실행에 성공하려면 제3자의 라이브러리를 가져오는 것 외에 그림 경로를 취향에 따라 처리해야 한다
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
js 마우스 이동 방향을 판단하는 방법PC 단말기의 마우스를 옮겨 옮기는 효과가 매우 좋다. 여기서 마우스를 옮겨 옮기는 방법을 판단하고 틈이 나면 효과가 있는 글을 보내지만 물고기를 주는 것보다 물고기를 잡는 것이 낫다. 이 방법이 있는데 효과가 so...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.