자바 QR 코드 생 성 및 url 링크 부여 기능 구현
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.0</version>
</dependency>
도구 클래스
public class YmtUtil {
public static byte[] getQRCodeImage(String text, int width, int height) throws
WriterException, IOException {
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width,
height);
ByteArrayOutputStream pngOutputStream = new ByteArrayOutputStream();
MatrixToImageWriter.writeToStream(bitMatrix, "PNG", pngOutputStream);
byte[] pngData = pngOutputStream.toByteArray();
return pngData;
}
기능 실현서비스 에 적 힌 코드 입 니 다.호출 하면 지정 한 저장 위치 에서 해당 하 는 QR 코드 를 찾 을 수 있 습 니 다.
// 192.168.0.21/erweima
String url = erweima;
// ip , ip
InetAddress localhost = StrUtil.getLocalHostExactAddress();
//
String URL= "http://localhost"+ url;
//
qrcode = YmtUtil.getQRCodeImage(URL, 360, 360);
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_PNG);
// linux :(/root/D:/opt/upFiles) window (D:/opt/upFiles) linux
File path = new File("/root/D:/opt/upFiles", + ".jpg");
//
ByteArrayInputStream inputStream = new ByteArrayInputStream(qrcode);
MockMultipartFile file = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);
file.transferTo(path);
이상 은 자바 가 QR 코드 를 만 들 고 url 링크 를 부여 하 는 상세 한 내용 입 니 다.자바 가 QR 코드 를 만 드 는 것 에 관 한 자 료 는 다른 관련 글 을 주목 하 세 요!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.