jane7374015 妳好: 以下是我的寫法,妳參考一下吧:
// 我的環境是 BCB4,不清楚其它版本是否需要引入下列檔案?
#include "gifimage.hpp"
#include if(OpenPictureDialog1->Execute()){
bool SupportFiles = true;
Graphics::TBitmap *tmpBitmap = new Graphics::TBitmap(); AnsiString fName = OpenPictureDialog1->FileName;
AnsiString curExt = LowerCase(ExtractFileExt(fName)); if(curExt == ".gif"){
TGIFImage *GIF = new TGIFImage;
GIF->LoadFromFile(fName);
tmpBitmap->Assign(GIF);
delete GIF;
}else if(curExt == ".jpg" || curExt == ".jpeg"){
TJPEGImage *JPEG = new TJPEGImage;
JPEG->LoadFromFile(fName);
tmpBitmap->Assign(JPEG);
delete JPEG;
}else if(curExt == ".emf" || curExt == ".wmf"){
TMetafile *WMF = new TMetafile;
WMF->Width=Width;
WMF->Height=Height;
WMF->LoadFromFile(fName);
WMF->Enhanced = true; tmpBitmap->Height = WMF->Height;
tmpBitmap->Width = WMF->Width;
tmpBitmap->Canvas->Draw(0, 0, WMF);
delete WMF;
}else if(curExt == ".ico"){
TIcon *TheIcon = new TIcon(); TheIcon->LoadFromFile(fName);
tmpBitmap->Height = TheIcon->Height;
tmpBitmap->Width = TheIcon->Width;
tmpBitmap->Canvas->Draw(0, 0, TheIcon);
delete TheIcon;
}else if(curExt == ".bmp"){
tmpBitmap->LoadFromFile(fName);
}else{
ShowMessage("本程式尚未支援 " curExt " 類型的檔案!");
SupportFiles = false;
} if(SupportFiles){
Image1->Picture->Bitmap->Assign(tmpBitmap);
} delete tmpBitmap;
}
7 天天敲鍵盤 v 時時按滑鼠 8