对于.jpg图片的处理用哪些库比较好,我现在用的CImg,好像不太好用,有用过的可以推荐一下,谢了!

解决方案 »

  1.   

    不好用是怎么了呢?
    可以自己写一个CImageEx ^_^
    实现放大缩小~
      

  2.   

    哦,是因为我少装了一个软件,不过还是有好多不明白的地方希望用过CImg的留个联系方式,有不懂的地方想请教一下,谢谢了!
      

  3.   

    intel 的 IJL15.DLL/*****************************************************
    从文件中将jpg图片转换为DIB 到内存中
    将内存中的DIB转换为JPG格式并保存为文件格式
    created by Bzero.lee   
    create time: 20060610
    需要intel的ijl.h和IJL15.DLL以及ijl15.lib
    MSN: [email protected]
    *******************************************************/#if !defined(MY_JPG_H)
    #define MY_JPG_H
    #include<string>
    using namespace std;
    class Jpg
    {
    public:
    static bool ReadImage(int& nWidth,                          // 字节补齐后的宽度
                       int& nOrignalWidth,                //原始宽度
                           int& nHeight,                     // 图片的高度
                           int& nChannels,                  // 每个像素所站的比特
                       BYTE *buffer,                   // 读取图片的内存
                       const string& strJpgFile); //Jpg文件的路径

    static bool WriteImage( BYTE* buffer,             // 要写入的地址
                        const int nWidth,         // 宽度
                        const int nHeight,         // 高度
                        const int nChannels,      // 每个象素所占的字节
                        const string& strJpgFile, //保存jpg图片的地址
                        bool bUpSet = true,
        int quality=75);          // 图片的压缩率    static int AlignWidth(const int& nOrignalWide); //对齐字节数 ilj库只能读取4字节的整数倍};#endif  //MY_JPG_H///////////////////////////实现部分///////////////////////////#include "StdAfx.h"
    #include "jpg.h"
    #include "ijl.h" 
    //读取jpg图片到内存中
    //返回值 false 读取错误
    //       true  成功
    bool Jpg::ReadImage(int& nWidth,   // 字节补齐后的宽度
    int& nOrignalWidth,//原始宽度
    int& nHeight,  // 图片的高度
    int& nChannels,// 每个像素所站的比特
    BYTE *buffer, // 读取图片的内存
    const string& strJpgFile) //Jpg文件的路径
    {
    JPEG_CORE_PROPERTIES jcprops;


    if ( ijlInit(&jcprops) != IJL_OK )
    {
    ijlFree(&jcprops);
    return false;
    }
    jcprops.JPGFile = strJpgFile.c_str();
    if ( ijlRead(&jcprops, IJL_JFILE_READPARAMS) != IJL_OK )
    {
    ijlFree(&jcprops);
    return false;
    }

    nOrignalWidth  = jcprops.JPGWidth;
    nWidth = AlignWidth(nOrignalWidth);
    nHeight = jcprops.JPGHeight;

    nChannels = jcprops.JPGChannels;


    if(NULL != buffer)
    {
    IJLIOTYPE mode;
    mode = IJL_JFILE_READWHOLEIMAGE;
    jcprops.JPGBytes = buffer;
    jcprops.jquality = 100;
    if ( !buffer )
    {
    ijlFree(&jcprops);
    return false;
    }

    jcprops.DIBWidth  = nWidth;
    jcprops.DIBHeight = -nHeight;
    jcprops.DIBChannels = nChannels;
    jcprops.DIBPadBytes = 0;
    jcprops.DIBBytes = buffer;

    if ( jcprops.JPGChannels == 3 )
    {
    jcprops.DIBColor = IJL_RGB;
    jcprops.JPGColor = IJL_YCBCR;
    jcprops.JPGSubsampling = IJL_411;
    jcprops.DIBSubsampling = (IJL_DIBSUBSAMPLING) 0;
    }
    else
    {
    jcprops.DIBColor = IJL_G;
    jcprops.JPGColor = IJL_G;
    jcprops.JPGSubsampling = (IJL_JPGSUBSAMPLING) 0;
    jcprops.DIBSubsampling = (IJL_DIBSUBSAMPLING) 0;
    }

    if ( ijlRead(&jcprops, mode) != IJL_OK )
    {
    ijlFree(&jcprops);
    return false;
    }

    }

    if ( ijlFree(&jcprops) != IJL_OK ) 
    return false;

    return true;
    }//写jpg到指定的文件夹中去
    //返回值 false  写文件错误
    //       true   写文件成功
    bool Jpg::WriteImage(BYTE* buffer, // 要写入的地址
     const int nWidth, // 宽度
     const int nHeight, // 高度
     const int nChannels, // 每个象素所占的字节
     const string& strJpgFile, //保存jpg图片的地址
     bool bUpSet,       //设置图片是否倒转
     int quality) // 图片的压缩率
    {
    JPEG_CORE_PROPERTIES jcprops;
    if ( ijlInit(&jcprops) != IJL_OK )
    {
    ijlFree(&jcprops);
    return false;
    }
    jcprops.DIBWidth    = nWidth;
        if(true == bUpSet)
    jcprops.DIBHeight   = -nHeight;
    else
    jcprops.DIBHeight   = nHeight;
    jcprops.JPGWidth    = nWidth;
    jcprops.JPGHeight   = nHeight;
    jcprops.DIBBytes    = buffer;
    jcprops.DIBPadBytes = 0;
    jcprops.DIBChannels = nChannels;
    jcprops.JPGChannels = nChannels;
    jcprops.JPGFile = strJpgFile.c_str();

    if (3 == nChannels)
    {
    jcprops.DIBColor = IJL_RGB;
    jcprops.JPGColor = IJL_YCBCR;
    jcprops.JPGSubsampling = IJL_411;
    jcprops.DIBSubsampling = (IJL_DIBSUBSAMPLING) 0;
    }
        else
    {
    jcprops.DIBColor = IJL_G;
    jcprops.JPGColor = IJL_G;
    jcprops.JPGSubsampling = (IJL_JPGSUBSAMPLING) 0;
    jcprops.DIBSubsampling = (IJL_DIBSUBSAMPLING) 0;
    }
    int size = nWidth * nHeight * nChannels;
    jcprops.JPGSizeBytes = size;
    jcprops.JPGBytes  = buffer;
    jcprops.jquality = quality;

    if ( ijlWrite(&jcprops, IJL_JFILE_WRITEWHOLEIMAGE) != IJL_OK )
    {
    ijlFree(&jcprops);
    return false;
    }


    if ( ijlFree(&jcprops) != IJL_OK )
    return false;
    return true;
    }//字节对齐
    //返回补齐四字节后的大小及4的倍数
    int Jpg::AlignWidth(const int& nOrignalWidth)
    {

    int nWidth;
    if(0 == nOrignalWidth % 4)
    {
    nWidth = nOrignalWidth;
    }
    else
    {
    nWidth = nOrignalWidth + 4 - nOrignalWidth % 4;
    }
        return nWidth;
    }