由于需要经常存储摄像头捕捉到的bmp数据,bmp数据没有经过压缩,每一张都很大,存储到一定空间的时候就需要删除一部分,非常麻烦.如果存储的bmp图像数据不需要做特殊处理,可以将其存为jpg格式.会节省很多空间.
使用GDI+:
</pre><pre name="code" class="html">#include "gdiplus.h"
using namespace Gdiplus;
//全局变量
GdiplusStartupInput m_Gdistart;
ULONG_PTR m_GdiplusToken;
//初始化
GdiplusStartup(&m_GdiplusToken,& m_Gdistart,NULL);
//程序结束
GdiplusShutdown(m_GdiplusToken);
上面是基本配置
void CXXX::SaveBmp2Jpg(char* filename)
{
BITMAPFILEHEADER bfh;
bfh.bfType = 19778;
bfh.bfSize = imwidth * imheight * nCount;
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
bfh.bfOffBits = 54;
BITMAPINFOHEADER bih;
bih.biSize = 40;
bih.biWidth = imwidth;
bih.biHeight = imheight;
bih.biPlanes = 1; //must be set to 1
bih.biBitCount = 24;
bih.biCompression = 0;
bih.biSizeImage = (imwidth*nCount*8+31)/32*nCount*imheight;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
b

最低0.47元/天 解锁文章
3278

被折叠的 条评论
为什么被折叠?



