生成带字符激活码并移植到空白图片上

本文详细介绍了从Excel文件中读取激活码与卡号数据,使用Java进行条形码生成,以及将条形码整合到图片并压缩为zip文件的过程。涉及关键技术包括Excel数据读取、条形码生成、图片处理和文件压缩。

// ===============================================================================================
// 激活码路径
String jihuomafilePath = “C:\image\JHM.xlsx”;
File excelFile = new File(jihuomafilePath);
JSONArray jihuomaJson = null;
try {
jihuomaJson = ExcelReader.load(excelFile).toJSON();
} catch (Exception e) {
LOGGER.error(“读取Excel失败”, e);
throw new ServiceException(e);
}

    // 卡号路径
    String kahaoFilePath = "C:\\image\\KH.xlsx";
    File kahaoExcelFile = new File(kahaoFilePath);
    JSONArray kahaoJson = null;
    try {
        kahaoJson = ExcelReader.load(kahaoExcelFile).toJSON();
    } catch (Exception e) {
        LOGGER.error("读取Excel失败", e);
        throw new ServiceException(e);
    }
    // ===============================================================================================

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

        // 拿到第一行数据
        Object jihuo = jihuomaJson.get(i);
        Object kahao = kahaoJson.get(i);
        JSONArray jihuoJsonArray = (JSONArray) jihuo;
        JSONArray kahaoJsonArray = (JSONArray) kahao;

        // 拿到第一列的数据
        Object jihuoColumnValue = jihuoJsonArray.get(0);
        Object KahaoColumnValue = kahaoJsonArray.get(0);

        // 对数据转型
        String jihuoValue = String.valueOf(jihuoColumnValue);
        String kahaoValue = String.valueOf(KahaoColumnValue);
        // ===============================================================================================
        String codeVelue;
        codeVelue = jihuoValue;
        logger.info("================获取到第" + i +"个激活码:"+ codeVelue);
        BufferedImage image;
        image = getBarCodeImage(codeVelue);
        // 创建一张空白图片,作为背景板
        BufferedImage image2 = new BufferedImage(2678, 189, BufferedImage.TYPE_3BYTE_BGR);
        // 得到空白图片
        Graphics graphics = image2.getGraphics();
        // 设置颜色填充背景板
        graphics.setColor(Color.white);
        // 矩形区域大小
        graphics.fillRect(0, 0, 2678, 189);
        // 将条形码移植
        graphics.drawImage(image, 645, 10, null);

        // 设置字体
        graphics.setColor(Color.BLACK);
        graphics.setFont(new Font("宋体",Font.PLAIN, 40));
        graphics.drawString(codeVelue, 1091, 185);


        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ImageIO.write(image2, "png", outputStream);
        logger.info("================将图片流输出到字节数组:outputStream = "+ outputStream);
        byte[] bytes = outputStream.toByteArray();

        ByteArrayInputStream inputStream1 = new ByteArrayInputStream(bytes);
        try {
            Zip4jUtil.addStreamToZip(inputStream1,kahaoValue+".png",vipAcZipFilePath,String.valueOf(acId));
        } catch (ZipException e) {
            e.printStackTrace();
        }
        /*String fileUrl = "d:\\test.png";
        FileOutputStream fout = new FileOutputStream(fileUrl);
        fout.write(bytes);
        fout.close();*/
    }

===========================================================================
private BufferedImage getBarCodeImage(String codeValue) {

    /*// 配置文件设定宽高
    Integer width = Integer.valueOf(PropertyConfigurer.getProperties("activation.code.key.max.width"));
    if (Objects.isNull(width) || Objects.equals(Integer.valueOf(width), 0)) {
        throw new ParameterException("条形码参数错误");
    }
    Integer height = Integer.valueOf(PropertyConfigurer.getProperties("activation.code.key.min.height"));
    if (Objects.isNull(height) || Objects.equals(Integer.valueOf(height), 0)){
        throw new ParameterException("条形码参数错误");
    }*/
    HashMap<EncodeHintType, Object> hints = new HashMap<>();
    hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
    hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
    hints.put(EncodeHintType.MARGIN, 2);
    BarcodeFormat bFmat;
    bFmat = BarcodeFormat.CODE_128;
    try {
        BitMatrix bitMatrix = new MultiFormatWriter().encode(codeValue, bFmat, 1389, 142, hints);
        BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
        return image;
    } catch (Exception e) {
        e.printStackTrace();
        logger.error("条形码生成错误", e);
    }
    return null;
}
内容概要:本资源聚焦于配电网在发生故障后的两阶段鲁棒恢复研究,旨在提升电力系统在不确定性条件下的恢复能力与运行可靠性。研究采用两阶段优化方法,第一阶段进行预恢复决策,如网络重构、分布式电源出力调整等,以最小化预期损失;第二阶段则针对实际发生的故障场景实施校正控制,利用鲁棒优化理论应对负荷波动、新能源出力不确定性等因素,确保恢复方案的可行性与强健性。资源提供了完整的Matlab代码实现,复现了相关顶刊研究成果,便于使用者深入理解模型构建、算法求解及仿真分析全过程。; 适合人群:具备电力系统分析、优化理论基础及Matlab编程能力的研究生、科研人员及电力行业工程师。; 使用场景及目标:① 学习掌握配电网故障恢复的先进优化方法,特别是两阶段鲁棒优化模型的构建与应用;② 复现和验证顶刊论文中的算法,为自身科研工作提供技术参考和代码基础;③ 将所学方法拓展应用于微电网、主动配电网等新型电力系统的可靠性评估与优化调度研究。; 阅读建议:学习者应结合提供的Matlab代码,仔细研读模型的数学公式与求解逻辑,重点关注不确定性建模、两阶段决策变量的设定以及鲁棒对等转换技巧。建议在掌握基础案例后,尝试修改参数或引入新的约束条件进行扩展研究,以深化理解提升创新能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值