对于.jpg图片的处理用哪些库比较好,我现在用的CImg,好像不太好用,有用过的可以推荐一下,谢了!
解决方案 »
- 几个全局变量在主线程与子线程被访问问题//
- 关于no appropriate default constructor available的问题
- vc中用sql判断某个物理文件或者数据表是否存在,要得到返回值
- 如何给命令响应添加快捷方式,例如ctrl + c代表复制
- PNG三态按钮
- BCGPPropertySheet怎么删除Tab?
- 怎么样就算熟悉TCP/IP协议了?说的详细者,最少50分. 不够可以再加
- 关于编译选项的问题
- 我怎么 在一个TOOLBAR上加一个TIP 呢!!
- 为什么微软的很多结构体里都有个cbSize成员?? (⊙_⊙)??
- 哪有《如何使用BHO定制你的Internet Explorer浏览器》
- 如何将bmp图像的r,g,b,h,s,v都分解出来
可以自己写一个CImageEx ^_^
实现放大缩小~
从文件中将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;
}