Jpeglib开发笔记(二):JpegLib编译(ubutnu)和Demo

若该文为原创文章,未经允许不得转载
原博主博客地址:https://blog.csdn.net/qq21497936
原博主博客导航:https://blog.csdn.net/qq21497936/article/details/102478062
本文章博客地址:https://blog.csdn.net/qq21497936/article/details/103520523

目录

前言

JpegLib下载地址

JepgLib编译

步骤一:下载放到ubuntu编译文件件

步骤二:配置

步骤三:make

步骤四:make install

Demo

工程模板


JpegLib开发笔记

Jpeglib开发笔记(一):JpegLib库介绍、windows编译和Demo

Jpeglib开发笔记(二):JpegLib编译(ubutnu)和Demo

 

    Jpeglib开发笔记(二):JpegLib编译(ubutnu)和Demo

前言

前篇编译了windows上的,现编译ubuntu上的。

 

JpegLib下载地址

       https://www.ijg.org/

       点击对应文件即可下载,如下图:

(与windows下载的文件不同,windows是zip)

 

JepgLib编译

步骤一:下载放到ubuntu编译文件件

步骤二:配置

./configure --prefix /home/yang/compile/jpeg/jpeg-9c/install

步骤三:make

步骤四:make install

 

Demo

解码测试运行成功,如下图:

在Qt项目中配置链接库的路径,添加环境变量LD_LIBRARY_PATH(不然会报错,找不到链接库),如下图:

测试代码

#include "JpegManager.h"
#include <QDebug>

JpegManager::JpegManager(QObject *parent)
    : QObject(parent)
{

}

void JpegManager::testDemo1(QString path)
{
    FILE *file;

    int width;
    int height;
    struct jpeg_decompress_struct jDecompressStruct;
    struct jpeg_error_mgr jErrorMgr;


    if ((file = fopen(path.toUtf8().data(), "rb")) == 0)
    {
      qDebug() << __FILE__ << __LINE__ << "Failed to open file:" << path;
      return;
    }

    // 初始化并申请解码器
    jDecompressStruct.err = jpeg_std_error(&jErrorMgr);
    jpeg_create_decompress(&jDecompressStruct);

    // 指定图片文件信息
    jpeg_stdio_src(&jDecompressStruct, file);

    // 读取头部信息
    jpeg_read_header(&jDecompressStruct, TRUE);

    // 开始解码
    jpeg_start_decompress(&jDecompressStruct);

    // 获取图片宽高
    width = jDecompressStruct.image_width;
    height = jDecompressStruct.image_height;

    qDebug() << __FILE__ << __LINE__ << "decompress file:" << path << width << "x" << height;
    printf("decompress file:%s, %d x %d\n", path.toUtf8().data(), width, height);

    // 释放解码器对象
    jpeg_destroy_decompress(&jDecompressStruct);

    fclose(file);
}

 

工程模板

       工程模板v1.0.0

 

若该文为原创文章,未经允许不得转载
原博主博客地址:https://blog.csdn.net/qq21497936
原博主博客导航:https://blog.csdn.net/qq21497936/article/details/102478062
本文章博客地址:https://blog.csdn.net/qq21497936/article/details/103520523

发布了227 篇原创文章 · 获赞 237 · 访问量 39万+

猜你喜欢

转载自blog.csdn.net/qq21497936/article/details/103520523