?
Hallo,
lade deine Bilder jpg,bmp,gif,png.. über ole:
... Code ...
// Read file in memory
fp = fopen(fileName,"rb");
if(!fp)
return;
BYTE *pMem = new BYTE[fs];
if(!pMem)
return ;
fread(pMem,1,fs,fp);
fclose(fp);
if(!StreamToPic(pMem,fs))
{
delete pMem;
return ;
}
delete pMem;
bool CDib::StreamToPic(BYTE *pMem, int Size, bool Flip/*=false*/)
{
// Use IPicture stuff to use JPG / GIF files
IPicture* pPicture = 0;
IStream* pStream = 0;
LPBYTE hG = 0;
HRESULT hRes = S_FALSE;
DWORD fs = Size;
hG = (LPBYTE) HeapAlloc( GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, fs);
if(!hG)
return hRes;
memcpy(hG,pMem,fs);
HRESULT hRes = ::CreateStreamOnHGlobal(hG,false,&pStream);// Create an IStream so IPicture can
if(hRes != S_OK)
{
HeapFree(GetProcessHeap(), 0, hG);
return hRes;
}
hRes = ::OleLoadPicture(pStream,fs,TRUE,IID_IPicture,(void**)&pPicture);
if(hRes != S_OK)
{
pStream->Release();
HeapFree(GetProcessHeap(), 0, hG);
return hRes;
}
short type;pPicture->get_Type(&type);
if(type == PICTYPE_BITMAP)
{
HBITMAP hBmp = 0;
hRes = pPicture->get_Handle( (OLE_HANDLE* )&hBmp);//Retrive GDI Object
if (hRes == S_OK)
{
CDib::Draw(hBmp, Flip);
}
if(hBmp)::DeleteObject(hBmp);
}
if(pStream)
pStream->Release();
if(hG)
HeapFree(GetProcessHeap(), 0, hG);
if(pPicture)
pPicture->Release();
return (hRes == S_OK);
}