在mfc 中读或者操作位图都很方便,可是遇到jpg等的压缩文件就很麻烦了。 下面是个函数可以把jpg文件做成HBITMAP的 然后就很容易显示了。缺点就是时间上又拖延。。
HBITMAP CMap2Dlg:: LoadJPG(CString strFileName)
{
IPicture* p=NULL;
IStream* s=NULL;
HGLOBAL hG;
void* pp;
FILE* fp;
// Read file in memory
fp = fopen(strFileName,"rb");
if (!fp)
return NULL;
fseek(fp,0,SEEK_END);
int fs = ftell(fp);
fseek(fp,0,SEEK_SET);
hG = GlobalAlloc(GPTR,fs);
if (!hG)
{
fclose(fp);
return NULL;
}
pp = (void*)hG;
fread(pp,1,fs,fp);
fclose(fp);
CreateStreamOnHGlobal(hG,false,&s);
if (!s)
{
GlobalFree(hG);
return NULL;
}
OleLoadPicture(s,0,false,IID_IPicture,(void**)&p);
if (!p)
{
s->Release();
GlobalFree(hG);
return NULL;
}
s->Release();
GlobalFree(hG);
HBITMAP hB = 0;
p->get_Handle((unsigned int*)&hB);
// Copy the image. Necessary, because upon p's release,
// the handle is destroyed.
HBITMAP hBB = (HBITMAP)CopyImage( hB,IMAGE_BITMAP,0,0,LR_COPYRETURNORG );
p->Release();
return hBB;
}

继续更新中。。。。。