-
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.io.UnsupportedEncodingException;import javax.imageio.ImageIO;import com.google.zxing.BarcodeFormat;import com.google.zxing.WriterException;import com.google.zxing.client.j2se.MatrixToImageConfig;import com.google.zxing.client.j2se.MatrixToImageWriter;import com.google.zxing.common.BitMatrix;import com.google.zxing.qrcode.QRCodeWriter;/*pom.xml에 추가한다.<dependency><groupId>com.google.zxing</groupId><artifactId>javase</artifactId><version>3.2.0</version></dependency>maven이 아닐경우 다음의 jar파일을 다운받아javase-x.x.x.jar 와 core-x.x.x.jar를 빌드패스에 추가한다.*/public class QRCodeTest {public static void main(String[] args) {String url = "http://m.naver.com";makeQRCode(url, 200, 200, ".", "daum");}/** QR코드 생성 유틸* @param url : QR 생성 URL* @param width : 폭* @param height : 높이* @param filePath : 폴더* @param fileName : 파일명*/public static void makeQRCode(String url, int width,int height,String filePath,String fileName){File file = null;try {// 경로가 존재하지 않으면 경로 생성file = new File(filePath);if(!file.exists()){file.mkdirs();}// UTF-8로 인코딩된 문자열을 ISO-8859-1로 생성url = new String(url.getBytes("UTF-8"),"ISO-8859-1");// QRCodeWriter객체 생성QRCodeWriter writer = new QRCodeWriter();BitMatrix matrix = writer.encode(url, BarcodeFormat.QR_CODE, width, height);// 배경색과 전경색 지정int foregroundColor = 0xFF000000;int backgroundColor = 0xFFAA0000;MatrixToImageConfig config = new MatrixToImageConfig(foregroundColor,backgroundColor);// BufferedImage 객체 생성BufferedImage qrImage = MatrixToImageWriter.toBufferedImage(matrix,config);// 이미지 저장ImageIO.write(qrImage, "png", new File(filePath+File.separator+fileName+".png"));} catch (UnsupportedEncodingException e) {e.printStackTrace();} catch (WriterException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}
cs zxing
Homepage : https://code.google.com/p/zxing/
source : https://github.com/zxing/zxing웹 상에서 QR코드 바로 만들 수 있는 URL
Homepage : http://mqr.kr/generate/url/jQuery QR 코드 만들기
Homepage : http://jeromeetienne.github.io/jquery-qrcode/
소스 : https://github.com/jeromeetienne/jquery-qrcode
blog : http://notes.jetienne.com/2011/04/07/jquery-qrcode.html'Java' 카테고리의 다른 글
005. HTML 파싱하기 - 네이버 실시간 급상승 검색어 (0) 2015.07.30 004. HTML 파싱하기 - 다음 실시간 이슈 (0) 2015.07.30 003. HTML 파싱하기 - 속성읽기 (0) 2015.07.29 002. HTML 파싱하기 - 태그읽기 (0) 2015.07.29 001. HTML 파싱하기 - 준비하기 (0) 2015.07.29 댓글