改写为C++Builder的编码
//---------------------------------------------------------------------------
#include <vcl.h> #pragma hdrstop
#include "Unit1.h" #include <math.h> //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender) { int nHandle; nHandle = FileOpen("E:\\hnk-s01.dwg",fmOpenRead); FileSeek(nHandle,13,0); BITMAPFILEHEADER BmpHeader; int nPosScen; FileRead(nHandle,&nPosScen,sizeof(__int32));
unsigned short nTypePreview; FileSeek(nHandle,nPosScen+30,0); FileRead(nHandle,&nTypePreview,1); ShowMessage(nTypePreview); int nPosBMP; int nLenBMP; short nBitCount; char* pszBuffer;
TMemoryStream* pms = new TMemoryStream(); Graphics::TBitmap *pBitmap = new Graphics::TBitmap();
switch (nTypePreview) { case 1: break; case 2: case 3: FileRead(nHandle, &nPosBMP, sizeof(__int32)); FileRead(nHandle, &nLenBMP, sizeof(__int32)); FileSeek(nHandle, nPosBMP+14, 0); FileRead(nHandle, &nBitCount,sizeof(__int16)); //ÒÆÖÁËõÂÔͼBMP¿ªÊ¼Î»Öà pszBuffer = new char[nLenBMP+1]; FileSeek(nHandle, nPosBMP, 0); ShowMessage(FileRead(nHandle,pszBuffer,nLenBMP)); FileClose(nHandle); BmpHeader.bfType = 0x4D42; if ( nBitCount < 9) BmpHeader.bfSize = 54+4*pow(2,nBitCount)+nLenBMP; else BmpHeader.bfSize = 54+nLenBMP; BmpHeader.bfReserved1 = 0; BmpHeader.bfReserved2 = 0; BmpHeader.bfOffBits = 14+0x28+1024; pms->Write(&BmpHeader.bfType, sizeof(BmpHeader.bfType)); pms->Write(&BmpHeader.bfSize, sizeof(BmpHeader.bfSize)); pms->Write(&BmpHeader.bfReserved1, sizeof(BmpHeader.bfReserved1)); pms->Write(&BmpHeader.bfReserved2, sizeof(BmpHeader.bfReserved2)); pms->Write(&BmpHeader.bfOffBits, sizeof(BmpHeader.bfOffBits)); pms->Write(pszBuffer,nLenBMP); pms->Seek(0,soFromBeginning );
//pBitmap->LoadFromStream(pms); //Image1->icture->Bitmap = pBitmap;
BitBtn1->Glyph->LoadFromStream(pms); break; }
} //--------------------------------------------------------------------------- |