qt之条形码与二维码的生成

news2024/9/20 1:10:05

一、简介

条形码:
    条形码(barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符。常见的条形码是由反射率相差很大的黑条(简称条)和白条(简称空)排成的平行线图案。本工程使用的是GNUBarCode库。

二维码:
    二维码又称二维条码,常见的二维码为QR Code,QR全称Quick Response,是一种编码方式。它比传统的Bar Code条形码能存更多的信息,也能表示更多的数据类型。本工程使用的是Libqrencode源码。

二、界面展示

在这里插入图片描述

二、核心代码

2.1 条形码 (ctbarcode.h、ctbarcode.cpp)

ctbarcode.h

#ifndef CTBARCODE_H
#define CTBARCODE_H

#include <QObject>
#include <QImage>
#include <QPainter>
#include "barcode.h"


#define  BAR_SAFE_FREE(p) \
do { \
    if(p) \
    { \
        free(p); \
        p = nullptr; \
    } \
} while(0)

class ctBarCode : public QObject
{
    Q_OBJECT
public:
    ctBarCode(QObject *parent = nullptr);
    ~ctBarCode();

    static ctBarCode& getInstance();

    //开始编码
    bool StartEncode(const QString& sTxt);
    //设置条码的类型
    void setBarcodeType(int nType);
    //设置条码四周留白区域的大小
    void setMargin(int nMargin);
    //设置是否在条码上/下面显示对应文字
    void setTxtShow(bool bTxtShow);

    //返回条码的尺寸
    QSize size();
    QSize minSize();

    //前景色
    QColor getFGColor() const;
    void setFGColor(const QColor& fgColor);

    //背景色
    QColor getBGColor() const;
    void setBGColor(const QColor& bgColor);

    //渲染绘制
    QImage paintImage(double dWidthScale = 2, int nHeight = 60, QImage::Format format = QImage::Format_RGB32);
    QImage paintImage(QSize size, QImage::Format format = QImage::Format_RGB32);
    bool render(QPainter &painter);
    bool render(QPainter &painter, QRect rect);

private:
    bool updateSizeInfo();
    bool drawBarCode(QPainter &painter);
    bool drawBarText(QPainter &painter);


private:
    Barcode_Item* m_pBcItem = nullptr;
    int m_nBcType = BARCODE_128;
    bool m_bTxtShow = false;
    QString m_sText;
    QColor m_fgColor = Qt::black;
    QColor m_bgColor = Qt::white;
    int m_nMargin = 5;
    int m_nMinWidth;
    int m_nMinHeight;
    int m_nGlobalWidth;
    int m_nGlobalHeight;

};

#endif // CTBARCODE_H

ctbarcode.cpp

#include "ctbarcode.h"
#include <math.h>


ctBarCode::ctBarCode(QObject *parent) : QObject (parent)
{
}

ctBarCode::~ctBarCode()
{
    if(m_pBcItem)
    {
        BAR_SAFE_FREE(m_pBcItem->ascii);
        BAR_SAFE_FREE(m_pBcItem->partial);
        BAR_SAFE_FREE(m_pBcItem->textinfo);
        BAR_SAFE_FREE(m_pBcItem->encoding);

        free(m_pBcItem);
    }
}

ctBarCode &ctBarCode::getInstance()
{
    static ctBarCode s_obj;
    return s_obj;
}

bool ctBarCode::StartEncode(const QString &sTxt)
{
    if(m_pBcItem)
    {
        BAR_SAFE_FREE(m_pBcItem->ascii);
        BAR_SAFE_FREE(m_pBcItem->partial);
        BAR_SAFE_FREE(m_pBcItem->textinfo);
        BAR_SAFE_FREE(m_pBcItem->encoding);

        free(m_pBcItem);
    }

    m_pBcItem = Barcode_Create(static_cast<char*>(sTxt.toLocal8Bit().data()));
    if(m_pBcItem)
    {
        m_pBcItem->margin = m_nMargin;

        int nFlags;
        if(m_bTxtShow)
        {
            nFlags = m_nBcType;
        }
        else
        {
            nFlags = m_nBcType | BARCODE_NO_ASCII;
        }
        m_pBcItem->flags = nFlags;

        Barcode_Encode(m_pBcItem, nFlags);

        updateSizeInfo();

    }
    else
        return false;

    return true;
}

void ctBarCode::setBarcodeType(int nType)
{
    m_nBcType = nType;
}

void ctBarCode::setMargin(int nMargin)
{
    m_nMargin = nMargin;
}

void ctBarCode::setTxtShow(bool bTxtShow)
{
    m_bTxtShow = bTxtShow;
}

QSize ctBarCode::size()
{
    return QSize(m_nGlobalWidth, m_nGlobalHeight);
}

QSize ctBarCode::minSize()
{
    if(m_pBcItem)
        return QSize(m_pBcItem->width, m_pBcItem->height);

    return QSize();
}

QColor ctBarCode::getFGColor() const
{
    return m_fgColor;
}

void ctBarCode::setFGColor(const QColor &fgColor)
{
    m_fgColor = fgColor;
}

QColor ctBarCode::getBGColor() const
{
    return m_bgColor;
}

void ctBarCode::setBGColor(const QColor &bgColor)
{
    m_bgColor = bgColor;
}

QImage ctBarCode::paintImage(double dWidthScale, int nHeight, QImage::Format format)
{
    if(!m_pBcItem)
        return QImage();

    int bcWidth = m_pBcItem->width; // 保存现场
    int bcHeight = m_pBcItem->height;
    float bcScalef = static_cast<float>(m_pBcItem->scalef);

    m_pBcItem->width = static_cast<int>(m_pBcItem->width * dWidthScale);
    m_pBcItem->scalef = dWidthScale;
    m_pBcItem->height = nHeight;

    int w = m_pBcItem->width + 2 * m_pBcItem->margin;
    int h = m_pBcItem->height + 2 * m_pBcItem->margin;

    QImage img(w, h, format);
    QPainter painter(&img);
    img.fill(m_bgColor);
    painter.setBrush(m_fgColor);
    render(painter);

    m_pBcItem->width = bcWidth; // 恢复原状
    m_pBcItem->height = bcHeight;
    m_pBcItem->scalef = static_cast<double>(bcScalef);
    return img;
}

QImage ctBarCode::paintImage(QSize size, QImage::Format format)
{
    if(!m_pBcItem)
        return QImage();

    int nWidth = size.width();
    int nHeight = size.height();
    return paintImage(nWidth / m_pBcItem->width, nHeight, format);
}

bool ctBarCode::render(QPainter &painter)
{
    if(!m_pBcItem)
        return false;

    int w = m_pBcItem->width + 2 * m_pBcItem->margin;
    int h = m_pBcItem->height + 2 * m_pBcItem->margin;
    painter.fillRect(QRect(0, 0, w, h), m_bgColor);

    if (!m_pBcItem->partial || !m_pBcItem->textinfo)
    {
        m_pBcItem->error = EINVAL;
        return false;
    }
    drawBarCode(painter);

    if(!(m_pBcItem->flags & BARCODE_NO_ASCII) )
    {
        drawBarText(painter);
    }
    return true;
}

bool ctBarCode::render(QPainter &painter, QRect rect)
{
    int xoffset = m_pBcItem->xoff;
    int yoffset = m_pBcItem->yoff;
    int width = m_pBcItem->width;
    int height = m_pBcItem->height;
    double scalef = m_pBcItem->scalef;

    m_pBcItem->xoff = rect.left();
    m_pBcItem->xoff = rect.top();
    m_pBcItem->width = rect.width() - 2 * m_nMargin;
    m_pBcItem->height = rect.height() - 2 * m_nMargin;
    m_pBcItem->scalef = 0.0;

    updateSizeInfo();
    bool ret = render(painter);

    m_pBcItem->xoff = xoffset;
    m_pBcItem->yoff = yoffset;
    m_pBcItem->width = width;
    m_pBcItem->height = height;
    m_pBcItem->scalef = scalef;

    return ret;
}

bool ctBarCode::updateSizeInfo()
{
    if(!m_pBcItem)
        return false;

    if (!m_pBcItem->partial || !m_pBcItem->textinfo )
    {
        m_pBcItem->error = EINVAL;
        return false;
    }

    //1.计算nBarLen
    int nBarLen = m_pBcItem->partial[0] - '0';
    for (char * ptr = m_pBcItem->partial + 1; *ptr; ptr++)
    {
        if (isdigit(*ptr))
        {
            nBarLen += (*ptr - '0');
        }
        else if (islower(*ptr))
        {
            nBarLen += (*ptr - 'a' + 1);
        }
    }

    m_nMinWidth = nBarLen; // 这个宽度是计算出的最小宽度
    m_nMinHeight = 80; // 默认的高度

    //The scale factor depends on bar length
    if ((fabs(m_pBcItem->scalef) < 1e-6))
    {
        if (!m_pBcItem->width)
        {
            m_pBcItem->width = nBarLen;
        }
        m_pBcItem->scalef = static_cast<double>(m_pBcItem->width) / static_cast<double>(nBarLen);
    }

    //The width defaults to "just enough"
    if (!m_pBcItem->width)
    {
        m_pBcItem->width = static_cast<int>(nBarLen * m_pBcItem->scalef) + 1;
    }

    //But it can be too small, in this case enlarge and center the area
    if (m_pBcItem->width < nBarLen * m_pBcItem->scalef)
    {
        int nWidth = static_cast<int>(nBarLen * m_pBcItem->scalef + 1);
        m_pBcItem->xoff -= (nWidth - m_pBcItem->width) / 2 ;
        m_pBcItem->width = nWidth;

        //Can't extend too far on the left
        if (m_pBcItem->xoff < 0)
        {
            m_pBcItem->width += -m_pBcItem->xoff;
            m_pBcItem->xoff = 0;
        }
    }

    //The height defaults to 80 points (rescaled)
    if (!m_pBcItem->height)
    {
        m_pBcItem->height = static_cast<int>(80 * m_pBcItem->scalef);
    }

    //If too small (5 + text), reduce the scale factor and center
    int nIndex = 5 + 10 * ((m_pBcItem->flags & BARCODE_NO_ASCII) == 0);
    if (m_pBcItem->height < nIndex * m_pBcItem->scalef)
    {
        double scaleg = (static_cast<double>(m_pBcItem->height)) / nIndex;
        int wid = static_cast<int>(m_pBcItem->width * scaleg / m_pBcItem->scalef);
        m_pBcItem->xoff += ( m_pBcItem->width - wid ) / 2;
        m_pBcItem->width = wid;
        m_pBcItem->scalef = scaleg;
    }

    m_nMargin = m_pBcItem->margin;
    m_nGlobalWidth  = m_pBcItem->xoff + m_pBcItem->width  + 2 * m_pBcItem->margin;
    m_nGlobalHeight = m_pBcItem->yoff + m_pBcItem->height + 2 * m_pBcItem->margin;

    return true;
}

bool ctBarCode::drawBarCode(QPainter &painter)
{
    int nnMode = '-';
    int i, j;
    char* ptr;
    double x0, y0, yr;
    double xpos = m_pBcItem->margin + (m_pBcItem->partial[0] - '0') * m_pBcItem->scalef;
    for (ptr = m_pBcItem->partial + 1, i = 1; *ptr; ptr++, i++)
    {
        //special cases: '+' and '-'
        if (*ptr == '+' || *ptr == '-')
        {
            nnMode = *ptr;
            i++;
            continue;
        }

        if (isdigit (*ptr))
            j = *ptr - '0';
        else
            j = *ptr - 'a' + 1;

        if (i % 2)
        {
            x0 = m_pBcItem->xoff + xpos;
            y0 = m_pBcItem->yoff + m_pBcItem->margin;
            yr = m_pBcItem->height;
            if( !(m_pBcItem->flags & BARCODE_NO_ASCII))
            {
                //leave space for text
                if (nnMode == '-')
                {
                    //text below bars: 10 points or five points
                    yr -= (isdigit(*ptr) ? 10 : 5) * m_pBcItem->scalef;
                }
                else
                {
                    //text above bars: 10 or 0 from bottom, and 10 from top
                    y0 += (isdigit(*ptr) ? 10 : 0) * m_pBcItem->scalef;
                    yr -= (isdigit(*ptr) ? 20 : 10) * m_pBcItem->scalef;
                }
            }
            painter.fillRect(QRect(static_cast<int>(x0), static_cast<int>(y0),
                                   static_cast<int>((j * m_pBcItem->scalef)), static_cast<int>(yr)), m_fgColor);
        }
        xpos += j * m_pBcItem->scalef;
    }
    return true;
}

bool ctBarCode::drawBarText(QPainter &painter)
{
    int nMode = '-';
    if (!(m_pBcItem->flags & BARCODE_NO_ASCII))
    {
        painter.save();
        painter.setPen(m_fgColor);

        for (char * ptr = m_pBcItem->textinfo; ptr; ptr = strchr(ptr, ' '))
        {
            while (*ptr == ' ')
                ptr++;

            if (!*ptr)
                break;

            if (*ptr == '+' || *ptr == '-')
            {
                nMode = *ptr; continue;
            }

            double f1, f2;
            char c;
            if (sscanf(ptr, "%lf:%lf:%c", &f1, &f2, &c) != 3)
            {
                continue;
            }
            painter.setFont(QFont("Helvetica", static_cast<int>(0.8 * f2 * m_pBcItem->scalef)));
            int x_pos = static_cast<int>(m_pBcItem->xoff + f1 * m_pBcItem->scalef + m_pBcItem->margin);

            int y_pos = 0;
            if(nMode == '-')
            {
                y_pos = m_pBcItem->yoff + m_pBcItem->margin + m_pBcItem->height ;//- 8 * m_pBcItem->scalef;
            }
            else
            {
                y_pos =  m_pBcItem->yoff + m_pBcItem->margin;
            }
            painter.drawText(QPoint(x_pos, y_pos ), QString(QChar(c)));
        }
        painter.restore();
    }
    return true;
}

2.2 二维码 (ctqrcode.h、ctqrcode.cpp)

ctqrcode.h

#ifndef CTQRCODE_H
#define CTQRCODE_H

#include <QObject>
#include <QImage>
#include <QPainter>
#include "qrencode.h"


class ctQrCode : public QObject
{
    Q_OBJECT
public:
    explicit ctQrCode(QObject* parent = nullptr);
    ~ctQrCode();

    static ctQrCode& getInstance();

    void startEncode(const QString& sTxt);
    void setTextShow(bool bTxtShow);
    void setFGColor(const QColor& fgColor);
    void setBGColor(const QColor& bgColor);

    QImage paintImage(int nWidth, int nHeight, QImage::Format format = QImage::Format_RGB32);
				
private:
    QRcode* m_pQRCode = nullptr;
    QString m_sText;
    int m_nWidth = 200;
    int m_nHeight = 200;
    QColor m_fgColor = Qt::black;
    QColor m_bgColor = Qt::white;
    bool m_bTxtShow = false;
};

#endif // CTQRCODE_H

ctqrcode.cpp

#include "ctqrcode.h"

ctQrCode::ctQrCode(QObject *parent) : QObject (parent)
{

}

ctQrCode::~ctQrCode()
{

}

ctQrCode &ctQrCode::getInstance()
{
    static ctQrCode s_obj;
    return s_obj;
}

void ctQrCode::startEncode(const QString &sTxt)
{
    if(sTxt.isEmpty())
        return;

    m_sText = sTxt;
    m_pQRCode = QRcode_encodeString(m_sText.toStdString().c_str(), 2, QR_ECLEVEL_Q, QR_MODE_8, 1);
}

void ctQrCode::setTextShow(bool bTxtShow)
{
    m_bTxtShow = bTxtShow;
}

void ctQrCode::setFGColor(const QColor &fgColor)
{
    m_fgColor = fgColor;
}

void ctQrCode::setBGColor(const QColor &bgColor)
{
    m_bgColor = bgColor;
}

QImage ctQrCode::paintImage(int nWidth, int nHeight, QImage::Format format)
{
    if(m_pQRCode)
    {
        qint32 nQrcodeWidth = m_pQRCode->width > 0 ? m_pQRCode->width : 1;
        double scale_x = static_cast<double>(nWidth) / static_cast<double>(nQrcodeWidth);
        double scale_y = static_cast<double>(nHeight) / static_cast<double>(nQrcodeWidth);

        int nOffset = 14;
        QImage img = QImage(nWidth + nOffset * 2, nHeight + nOffset * 2, format);
        QPainter painter(&img);
        img.fill(m_bgColor);
        painter.setPen(Qt::NoPen);//不显示轮廓
        painter.drawRect(nOffset, nOffset, nWidth, nHeight);
        painter.setBrush(m_fgColor);

        for (qint32 y = 0; y < nQrcodeWidth; y++)
        {
            for (qint32 x = 0; x < nQrcodeWidth; x++)
            {
                unsigned char b = m_pQRCode->data[y*nQrcodeWidth + x];
                if (b & 0x01)
                {
                    QRectF r(nOffset + x * scale_x, nOffset + y * scale_y, scale_x, scale_y);
                    painter.drawRects(&r, 1);
                }
            }
        }

        if(m_bTxtShow)
        {
            painter.setPen( QColor(210, 172, 61));
            painter.drawText(nWidth/2, nHeight+nOffset*2-2, m_sText);
        }
        QPixmap mainmap = QPixmap::fromImage(img);
        return img;
    }
    return QImage();
}

2.2 主界面 (mainwindow.h、mainwindow.cpp)

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_pushButton_bar_clicked();

    void on_pushButton_qr_clicked();

private:
    Ui::MainWindow *ui;

};

#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include "ctbarcode.h"
#include "ctqrcode.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_bar_clicked()
{
    QString sBarTxt = ui->lineEdit_bar->text();
    if(sBarTxt.isEmpty())
    {
        QMessageBox::critical(this, "myQBCode", "内容不能为空");
        return;
    }

    ctBarCode::getInstance().setBarcodeType(BARCODE_I25 | BARCODE_NO_CHECKSUM);
    if(ui->checkBox_bar->isChecked())
    {
        ctBarCode::getInstance().setTxtShow(true);
    }
    else
    {
        ctBarCode::getInstance().setTxtShow(false);
    }

    ctBarCode::getInstance().setMargin(10);
    ctBarCode::getInstance().StartEncode(sBarTxt);

    QImage barcode = ctBarCode::getInstance().paintImage(2, 80);
    ui->label_bar->setPixmap(QPixmap::fromImage(barcode));

}

void MainWindow::on_pushButton_qr_clicked()
{
    QString sQrTxt = ui->lineEdit_qr->text();
    if(sQrTxt.isEmpty())
    {
        QMessageBox::critical(this, "myQBCode", "内容不能为空");
        return;
    }

    if(ui->checkBox_qr->isChecked())
    {
        ctQrCode::getInstance().setTextShow(true);
    }
    else
    {
        ctQrCode::getInstance().setTextShow(false);
    }

    ctQrCode::getInstance().startEncode(sQrTxt);

    QImage qrcode = ctQrCode::getInstance().paintImage(200, 200);
    ui->label_qr->setPixmap(QPixmap::fromImage(qrcode));
}

三、工程链接下载

下载地址:https://download.csdn.net/download/linyibin_123/87449524

四、本文参考

https://blog.csdn.net/hhy321/article/details/120245679

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/344021.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

探讨接口测试以及其用例设计方法

接口测试的总结文档 第一部分&#xff1a;主要从问题出发&#xff0c;引入接口测试的相关内容并与前端测试进行简单对比&#xff0c;总结两者之前的区别与联系。但该部分只交代了怎么做和如何做&#xff1f;并没有解释为什么要做&#xff1f; 第二部分&#xff1a;主要介绍为什…

数据结构:带环单链表基础OJ练习笔记(leetcode142. 环形链表 II)(leetcode三题大串烧)

目录 一.前言 二.leetcode160. 相交链表 1.问题描述 2.问题分析与求解 三.leetcode141. 环形链表 1.问题描述 2.代码思路 3.证明分析 下一题会用到的重要小结论&#xff1a; 四.leetcode142. 环形链表 II 1.问题描述 2.问题分析与求解 Judgecycle接口&#xf…

婴儿监视器美国亚马逊CPC认证ASTM F2951标准要求?

婴儿监视器&#xff0c;又称婴儿监听器、婴儿监护器&#xff0c;英文名为( baby monitor其主要用于用于居家和婴儿的监听和护理。欧美市场上广泛使用&#xff0c;已经存在30年历史的 Baby Monitor是采用现代无线电技术应用于居家和婴儿的监听和护理的好帮手。婴儿监护器由看器(…

基于Jeecgboot前后端分离的ERP系统开发系列--出库单(1)

这次从出库单开始进行整个单据录入显示的模板&#xff0c;不再采用默认的online表单代码生成的方式&#xff0c;以满足实际的业务需要&#xff0c;当然刚开始做&#xff0c;以后还需要进行改进。 一、首先单号生成 采用系统开发里的代码编码规则&#xff0c;相应的修改增加代码…

7、MyBatis框架——MyBatis对一对一关系的处理、分步查询、MyBatis对一对多关系的处理

目录 一、项目框架搭建 二、在实体类中添加额外属性实现多表查询 1、mybatis两表关联查询 &#xff08;1&#xff09;实体类类型映射规则 &#xff08;2&#xff09;代码演示 2、分步查询 &#xff08;1&#xff09;autoMapping开启自动映射 &#xff08;2&#xff09;…

Python-正则表达式详解-快速掌握正则表达式核心函数

正则表达式为为高级的文本模式匹配、抽取或文本形式的搜索和替换功能提供了基础。本文主要介绍python正则表达式的一些基础功能&#xff0c;掌握它也可以使得在python编程中处理字符串游刃有余。1.简介正则表达式是一些由字符和特殊符号组成的字符串&#xff0c;匹配一系列有相…

Ansible的安装及部署

目录 一、Ansible对于企业运维的重大意义 二、Ansible的安装 三、构建Ansible清单 1.直接书写受管主机名或ip&#xff0c;每行一个 2.设定受管主机的组[组名称] 四、Ansible配置文件参数详解 1、配置文件的分类与优先级 2.配置新用户的Ansible配置 3.生成免密认证 本章…

算法 ——世界 二

个人简介&#xff1a;云计算网络运维专业人员&#xff0c;了解运维知识&#xff0c;掌握TCP/IP协议&#xff0c;每天分享网络运维知识与技能。个人爱好: 编程&#xff0c;打篮球&#xff0c;计算机知识个人名言&#xff1a;海不辞水&#xff0c;故能成其大&#xff1b;山不辞石…

Linux管道选取命令:cut、grep

选取命令就是将一段数据经过分析后&#xff0c;取出我们所想要的&#xff0c;或是经历分析关键词&#xff0c;取得我们所想要的那一行 一般来说&#xff0c;选取信息通常是针对一行一行来分析的&#xff0c;而不是整篇信息分析 下面介绍两个很常用的信息选取命令&#xff1a;…

Numpy基础与实例——人工智能基础——机器学习

文章目录一、Numpy概述1. 优势2. numpy历史3. Numpy的核心&#xff1a;多维数组4. 内存中的ndarray对象4.1 元数据&#xff08;metadata&#xff09;4.2 实际数据二、numpy基础1. ndarray数组2. arange、zeros、ones、zeros_like3. ndarray对象属性的基本操作3.1 修改数组维度3…

dubbo接口自动化用例性能优化

dubbo接口自动化用例性能优化 目录&#xff1a;导读 前言 优化本地调试时间 单用例执行时间的优化 提高并发 最后 前言 去年换了一个新部门&#xff0c;看了下当前的自动化用例的情况&#xff0c;发现存在三类性能问题&#xff1a; 本地调试运行时等待时间较长&#xf…

C++学习记录——팔 内存管理

文章目录1、动态内存管理2、内存管理方式operator new operator delete3、new和delete的实现原理1、动态内存管理 C兼容C语言关于内存分配的语法&#xff0c;而添加了C独有的东西。 //int* p1 (int*)malloc(sizeof(int));int* p1 new int;new是一个操作符&#xff0c;C不再需…

【工具】图片和PDF批量区域OCR识别图片文字并重命名,如何批量图片识别文字并将识别的文字改名该图片

前段时间接到一个棘手的难题&#xff08;识别图片文字&#xff0c;将图片文件名改成该文字&#xff09; 因为不解决就得手动挨个挨个输入然后把文件命名好 今天又一个文件需求是这样的 图上有姓名文字&#xff0c;要识别出来改成每一张图跟这个一样&#xff0c;有的人说了缩…

学习笔记——吴恩达《神经网络与深度学习》

神经网络与深度学习1. 基础知识神经网络用神经网络进行监督学习2. 神经网络基础知识二分分类logistic回归logistic回归损失函数梯度下降法导数计算图logistic回归中的梯度下降法m个样本的梯度下降向量化Python中的广播3. 浅层神经网络神经网络概述神经网络表示计算神经网络的输…

Android自动化测试——Monkey

本来是做Web后端的&#xff0c;来公司实习变成微信小程序前端了&#xff0c;到这周变成Android APP测试人员了&#xff0c;也是微醺啊。 由于对手工测试终究是有些抵触&#xff0c;所有昨天小试了一下不用写代码的自动化压力测试&#xff0c;在此记下我的心得。 一、Monkey与…

TOOM互联网舆情监测中心,互联网舆情监测系统为何出现以及由来?

互联网舆情监测中心是指负责收集、分析和评估互联网上的舆情信息的组织或机构&#xff0c;旨在帮助政府、企业、媒体和其他相关组织了解公众对特定话题的看法、情感和态度&#xff0c;并采取相应的措施应对和管理舆情事件&#xff0c;TOOM互联网舆情监测中心&#xff0c;互联网…

Hudi-集成Spark之spark-shell 方式

Hudi集成Spark之spark-shell 方式 启动 spark-shell &#xff08;1&#xff09;启动命令 #针对Spark 3.2 spark-shell \--conf spark.serializerorg.apache.spark.serializer.KryoSerializer \--conf spark.sql.catalog.spark_catalogorg.apache.spark.sql.hudi.catalog.Hoo…

leaflet 本地上传shp文件,在map上解析显示图形(058)

第058个 点击查看专栏目录 本示例的目的是介绍演示如何在vue+leaflet中本地上传shp文件,利用shapefile读取shp数据,并在地图上显示图形。 直接复制下面的 vue+openlayers源代码,操作2分钟即可运行实现效果 文章目录 示例效果加载shapefile.js方式配置方式示例源代码(共126…

GBDT+LR

为什么需要GBDTLR 协同过滤和矩阵分解存在问题: 仅利用了用户与物品相互行为信息进行推荐&#xff0c; 忽视了用户自身特征&#xff0c; 物品自身特征以及上下文信息等&#xff0c;导致生成的结果往往会比较片面。 FFM 存在问题 FFM特征交叉能力有限&#xff1a;虽然 FFM 模型…

Excel里数字太长显示为科学计数法如何显示完整数字

Excel里数字太长显示为科学计数法如何显示完整数字 注意&#xff1a;以下测试都是在macos的Microsoft Excel for Mac的16.53版本中实际测试的&#xff0c;在windows中应该也是一样的。 一、问题描述 数字太长在Excel中会显示为E形式 有些值&#xff0c;比如身份证号、银行卡…