我希望在一个dialog上显示一个jpg图片,有没有代码可以参考阿
DentistryDoctor(My heart will fly,in the sky.) 于 2005-9-13 10:17:18
使用IPicture接口。 nkwesley(江南丝竹) 于 2005-9-13 10:38:42
给个函数 HBITMAP CTestDlg::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; } nkwesley(江南丝竹) 于 2005-9-13 10:40:27
上面这个函数使用很简单 HBITMAP hbmp; hbmp = LoadJPG( m_strFilePath );
f( hbmp != NULL) { m_bitmap.Detach(); m_bitmap.Attach(hbmp); } else { TRACE("\\n图像载入失败!"); return; } jxgjxgok 于 2005-9-13 10:41:34
用gdi+的Image轻松支持除tga格式以外的很多文件格式
jxgjxgok 于 2005-9-13 11:24:23
CRect rect; GetClientRect( rect ); Bitmap bmp( rect.Width( ),rect.Height( ) ); Graphics graphics( &bmp ); //CDC* pDC=GetDC( ); Graphics gFont( *pDC ); Image image(L"01.jpg"); graphics.DrawImage( &image,rect.left,rect.top,rect.right,rect.bottom);
gFont.DrawImage( &bmp,rect.left,rect.top,rect.right,rect.bottom );
microyzy(毛毛叉) 于 2005-9-14 15:58:39
嗯,同意GDI+,多用一个dll而已,却简单得多
(iwgh) |