问答详情
源自:6-4 使用QR Code方式生成和解析二维码

bufferedImage cannot be resolved to a type

package com.imooc.qrcode;


import java.awt.Color;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;


import javax.imageio.ImageIO;


import com.swetake.util.Qrcode;


public class CreateQRCode

{

public static void main(String[] args)

{

Qrcode x=new Qrcode();

x.setQrcodeErrorCorrect('M');//纠错等级

x.setQrcodeEncodeMode('B');//N代表数字 A代表a-Z B代表其他字符

x.setQrcodeVersion(7);//版本

String qrData="www.imooc.com";

int width=300;

int height=300;

BufferedImage bufferedImage=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);

Graphics2D gs=new bufferedImage.createGraphics();

gs.setBackground(Color.WHITE);

gs.setColor(Color.BLACK);

gs.clearRect(0, 0, width, height);

int pixoff=2;//偏移量

byte[] d=qrData.getBytes("gb2312");

if(d.length>0 && d.length<120)

{

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

for(int i=0;i<s.length;i++)

{

for(int j=0;j<s.length;j++)

{

if(s[i][j])

{

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

}

}

}

}

gs.dispose();

bufferedImage.flush();

ImageIO.write(bufferedImage, "png", "E:/img/qrcode.png");

}


}


提问者:BeShelby 2016-08-11 00:35

个回答

  • kiritolr
    2016-08-12 13:21:31

    把new 删掉 改成 Graphics2D gs = bufferedImage.createGraphics(); 

  • BeShelby
    2016-08-11 00:36:31

    http://img.mukewang.com/57ab57f40001b62c10730500.jpg这是我报错的界面。