注册 登录
编程论坛 JAVA论坛

ImageIO不正常工作,点出write就报错

Ycx0721 发布于 2022-10-05 21:55, 1503 次点击
    ImageIO不正常工作,点出write就报错
package com.ycx.qrcode;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import
import java.util.HashMap;
import java.util.Map;

public class TestQrcode {
    public static void main(String[] args) throws WriterException {
        //core.3.3.jar Zxing
        //创建一个画者
        MultiFormatWriter mfw = new MultiFormatWriter();
        //内容,类型,宽度,高度,其他信息map
        String content = "我爱我自己";
        BarcodeFormat type = BarcodeFormat.QR_CODE;
        int width = 600;
        int height = 600;
        Map map = new HashMap();
        map.put(EncodeHintType.CHARACTER_SET, "Utf-8");
        map.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        map.put(EncodeHintType.MARGIN, 2);
        //画一个虚拟的二维码对象
        BitMatrix matrix = mfw.encode(content, type, width, height, map);
        //流虚拟二维码对象的信息写入文件

        int black = Color.BLACK.getRGB();
        int white = Color.BLACK.getRGB();

        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                image.setRGB(x, y, matrix.get(x,y)?black:white);
            }
        }
    }
    File file=new File("D://alljavafile//ideajavafile//zzt.png");
    ImageIO.//在这里报错了
}
0 回复
1