返回> 网站首页 

IJL库的使用(BMP压缩成JPG)

yoours2011-05-06 10:30:47 阅读 1232

简介一边听听音乐,一边写写文章。

class CImageJpgBmp//处理图像编码和解码工作的类

//首先加载文件

#include "ijl.h"

       IJLERR                      m_jerr;//错误枚举类型

       JPEG_CORE_PROPERTIES m_jcprops;//设置图像属性的结构体

//初始化和卸载库是必不可少的

m_jerr = ijlInit(&m_jcprops);

       if(IJL_OK != m_jerr)//初始化显示错误提示

       {            

       AfxMessageBox((LPCTSTR)ijlErrorStr(m_jerr),MB_OK,NULL);//ijlErrorStr---Return a pointer to a string with error description.

              return FALSE;

       }

       ijlFree(&m_jcprops);

//然后就是最关键的两个函数,编码和解码函数

BOOL CImageJpgBmp::EncodeToJPEGBuffer(BYTE* pRgbBuffer,DWORD dwWidth,DWORD dwHeight,BYTE* pJpgBuffer,DWORD &dwJpgBufferSize)

{

       DWORD   dwRgbBufferSize = dwWidth * dwHeight;//计算出存放图像数据的最大空间

       // Set up the info on the desired DIB properties.

       m_jcprops.DIBBytes       = pRgbBuffer;

      

       m_jcprops.DIBWidth       = dwWidth;

       m_jcprops.DIBHeight      = dwHeight; // Implies a bottom-up DIB.

       m_jcprops.DIBPadBytes    = 0;

      

       m_jcprops.DIBChannels    = 1;//单通道图像表示一个字节就是一个像素,-3标识-3个字节表示一个像素

       m_jcprops.DIBColor       = IJL_G;

       m_jcprops.DIBSubsampling = IJL_NONE;//通道数决定的

       //目标JPG图像的设置

       m_jcprops.JPGFile        = NULL;

       m_jcprops.JPGSizeBytes   = dwRgbBufferSize;//Max buffer size.

       m_jcprops.JPGWidth       = dwWidth;

       m_jcprops.JPGHeight      = dwHeight;

       m_jcprops.JPGChannels    = 1;

       m_jcprops.JPGColor       = IJL_G;//灰度彩色空间Grayscale color space.

       m_jcprops.JPGSubsampling = IJL_NONE; // 4:1:1 subsampling   

       m_jcprops.JPGBytes       = pJpgBuffer;//Pointer to buffer based JPEG.

       m_jcprops.jquality          = 60; // Select "good" image quality-100

      

       m_jerr = ijlWrite(&m_jcprops,IJL_JBUFF_WRITEWHOLEIMAGE);

       if(IJL_OK != m_jerr)//发生错误提示信息

       {

       AfxMessageBox((LPCTSTR)ijlErrorStr(m_jerr),MB_OK,NULL);//ijlErrorStr---Return a pointer to a string with error description.

              return FALSE;

       }

       dwJpgBufferSize = m_jcprops.JPGSizeBytes;//供外部引用,计算数据量的大小

       return TRUE;

}

微信小程序扫码登陆

文章评论

1232人参与,0条评论