关于_java程序生成二维码_无logo

1.二维码生成方式一
package com.ama.aduan.test;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Scanner;
import javax.imageio.ImageIO;
import com.swetake.util.Qrcode;//这个包很关键
/**
* @author 手动输入 设置二维码
*
*/
public class TestMaTwo {
public static void main(String[] args) {
String content="";
Scanner sc=new Scanner(System.in);
System.out.println("在控制台编写你的名片信息\n 输入ok后,按enter结束");
while(! content.endsWith("ok")){
content=content+"\n";
content=content.concat(sc.next());
}
 
content=content.substring(1,content.length()-2);
 
System.out.println("给生成的二维码设置名字,按enter结束");
String filename=sc.next();
String filepath1="F:/二维码";
File file =new File(filepath1);
if(!file.exists()){
file.mkdir();
}
String filepath=filepath1+"/"+filename+".png";
new TestMain().drawQRCODE(content, filepath);
System.out.println("你的名片生成成功,在你的电脑F!");
 
}
public void drawQRCODE(String content,String filepath){
try {
Qrcode qrcode=new Qrcode();
qrcode.setQrcodeErrorCorrect('M');
qrcode.setQrcodeEncodeMode('B');
qrcode.setQrcodeVersion(15);
int width= 235;
int height=235;
BufferedImage image=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics2D g2=image.createGraphics();
g2.setBackground(Color.WHITE);
g2.clearRect(0,0,235,235);
g2.setColor(Color.BLACK);
 
byte[] contentbytes=content.getBytes("utf-8");
boolean[][] codeout= qrcode.calQrcode(contentbytes);
for (int i = 0; i <codeout.length; i++) {
for (int j = 0; j < codeout.length; j++) {
 
if (codeout[j][i]) g2.fillRect(j*3+2,i*3+2,3,3);
}
}
g2.dispose();
image.flush();
File imgFile = new File(filepath);
ImageIO.write(image, "png", imgFile);
}catch (Exception e){
e.printStackTrace();
}
}
}
展示:
 

转载于:https://www.cnblogs.com/yfduan/p/7999190.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值