当前位置: 首页 > news >正文

c++ zint二维码、条形码开发库

zint 是一个开源的条码编码库,它支持超过50种条码,包括 Code-128, Data Matrix, EAN-128, UPC/EAN, ITF, QR Code, Code 16k, PDF417, MicroPDF417, LOGMARS, Maxicode, GS1 DataBar, Aztec, Composite Symbols 等等,基本上你见过的条码都能用它来进行编码,它支持直接输出 PNG 格式的图像文件和位图的字节数组。

本人就zint封装以下接口,更容易使用:

#pragma once

#include "TypeDef.h"

class COMMONMDBENGINE_DLL_CLASS BarcodeUtil
{
public:
    
    BarcodeUtil();

    ~BarcodeUtil();

    void CreatInstance();

    void setSymbology(Symbology symbology);

    // 设置文本
    void setContent(const std::string& content);

    //高度
    void setWidth(int width);

    //高度
    void setHeight(float height);

    //条形码尺寸的缩放因子
    void setScale(float scale);

    //边框的宽度
    void setBorderWidth(int width);

    // 编码内容并生成位图数据 (返回 RGB 数据或其他格式)
    std::vector<unsigned char> generateBarcodeBitmap(const std::string& content);

    // 将条码保存为图片文件 (需要实现,可能依赖其他库如 libpng)
    bool saveToFile(const std::string& filename, int dpi = 72); // PNG 格式

    //条码前景颜色,格式为RGB16进制的字符串,例如,绿色“00FF00
    void setfgcolour(const std::string& strfgcolour);

    void setbgcolour(const std::string& strbgcolour);

    //一般为版本大小
    void setoption_2(int noption_2);

    //一般为校验等级
    void setoption_1(int noption_1);

    void setoption_3(int noption_3);

    //左右空白的宽度
    void setwhitespace_width(int nwidth);

    void setwhitespace_height(int nheight);

    //条码是否添加边框或边界线
    void setoutput_options(int noutput_options);

    void setoutfile(string strPath);

    int Print(int rotate_angle = 0);

};

使用示例:


    {
        BarcodeUtil barcodeGen;
        barcodeGen.CreatInstance();
        barcodeGen.setSymbology(Symbology::CODE128B);
        barcodeGen.setScale(2.0f);
        barcodeGen.setoutfile("tiaoxingma.png");

        std::string strContent = "12345678";
        barcodeGen.setContent(strContent);

        barcodeGen.Print();
    }

    // 生成二维码
        {
            BarcodeUtil barcodeGen;
            barcodeGen.CreatInstance();
            barcodeGen.setSymbology(Symbology::QRCODE);
            barcodeGen.setScale(8.0f);
            barcodeGen.setoutfile("erweima.png");

            std::string strContent = "12345678";
            barcodeGen.setContent(strContent);

            barcodeGen.Print();
        }

http://www.dtcms.com/a/366019.html

相关文章:

  • c++多线程(1)------创建和管理线程td::thread
  • Python数据分析与处理(二):将数据写回.mat文件的不同方法【超详细】
  • AI+法律:用ERNIE-Bot解析合同条款,识别风险点
  • 进程管理和IPC
  • 常用假设检验方法及 Python 实现
  • 多层环境室内定位系统综述总结
  • 【JavaEE】(22) Spring 事务
  • 苏哒智能会议一体机:让会议管理进入智能时代
  • Java与Vue构建的企业设备资产管理系统,集成后台管理与移动端操作,覆盖设备全生命周期,支持采购、维护、报废等流程,提供完整源码,助力企业高效管控资产
  • 刻意练习实践说明使用手册
  • nginx配置讲解
  • GitLens:VS Code下高效解决代码追溯的Git管理实用插件
  • Spring Boot + Nacos 配置中心示例工程
  • ego(2)---初始轨迹生成后的关键点采样
  • 一文读懂线性回归的灵魂:成本函数 J(w,b) 全解析
  • K8s基于节点软亲和的高 CPU Pod 扩容与优先调度方案
  • 华为OD最新机试真题-二进制差异数-OD统一考试(C卷)
  • 《K8s网络策略与CNI插件交互问题分析:基于真实案例的排查方法》
  • 卷积操作原来分3种
  • (二)文件管理-基础命令-mkdir命令的使用
  • C++CSP-J/S必背模板
  • Estimating the Number of Sources: An Efficient Maximization Approach
  • 上下文记忆力媲美Genie3,且问世更早:港大和可灵提出场景一致的交互式视频世界模型!
  • Guidelines for using Adaptive Platform interfaces
  • redisson功能完整指南
  • 【OpenGL】LearnOpenGL学习笔记19 - 几何着色器 Geometry Shader
  • 【机器学习深度学习】RAG边界处理策略
  • Vision Pro图像处理工具全解析
  • ClickHouse使用Docker部署
  • 刷新记录:TapData Oracle 日志同步性能达 80K TPS,重塑实时同步新标准