Load JPEG,GIF files in VC++ :
Once again it is only for VC++ guys... To load JPEG in VC++ is a headache problem...
#include <ole2.h>
{
// Use IPicture stuff to use JPG / GIF files
IPicture* p;
IStream* s;
IPersistStream* ps;
HGLOBAL hG;
void* pp;
FILE* fp;
// Read file in memory
fp = fopen(FileName,"rb");
if (!fp)
return;
fseek(fp,0,SEEK_END);
int fs = ftell(fp);
fseek(fp,0,SEEK_SET);
hG = GlobalAlloc(GPTR,fs);
if (!hG)
{
fclose(fp);
return;
}
pp = (void*)hG;
fread(pp,1,fs,fp);
fclose(fp);
// Create an IStream so IPicture can
// CreateStreamOnHGlobal(hG,false
CreateStreamOnHGlobal(hG,false
if (!s)
{
GlobalFree(hG);
return;
}
OleLoadPicture(s,0,false,IID
if (!p)
{
s->Release();
GlobalFree(hG);
return;
}
s->Release();
GlobalFree(hG);
long hmHeight;
long hmWidth;
HBITMAP hB = 0;
p->get_Handle((unsigned int*)&hB);
p->get_Height(&hmHeight);
p->get_Width(&hmWidth);
p->Render(hdc,0,0,300,300,0
p->Release();
}
0 Comments:
Post a Comment
<< Home