打印图形的类,可图形有时能打印出来,有时就打印不出来 int CP::CreateBmp(int bw, int bh)//创建图像 { TLogPalette *lPal; int i; nos++; thebmp[nos] = new Graphics::TBitmap; thebmp[nos]->HandleType = bmDIB; thebmp[nos]->PixelFormat= pf1bit; i = sizeof(TLogPalette) + sizeof(TPaletteEntry) *10 ; lPal = (TLogPalette*) malloc(i); lPal->palVersion = 0x300; lPal->palNumEntries = 2; lPal->palPalEntry[0].peRed = 0 ; lPal->palPalEntry[0].peGreen = 0 ; lPal->palPalEntry[0].peBlue = 0 ; lPal->palPalEntry[0].peFlags = 0; lPal->palPalEntry[1].peRed =255; lPal->palPalEntry[1].peGreen =255; lPal->palPalEntry[1].peBlue =255; lPal->palPalEntry[1].peFlags = 0; thebmp[nos]->Palette = CreatePalette(lPal); thebmp[nos]->Width = bw*DotsPerMM; thebmp[nos]->Height = bh*DotsPerMM; bmpCan[nos] = thebmp[nos]->Canvas; free( lPal); return nos; } void CP::BmpCopy(int x, int y , int bmpindex) //把图形赋给打印机;bmpindex就是CreateBmp函数所返回的值,就是nos的值 { unsigned int BitmapInfoSize, BitmapImageSize; long DIBWidth, DIBHeight; PChar BitmapImage; Windows::PBitmapInfo BitmapInfo; x *= DotsPerMM; y *= DotsPerMM; prBrush->Style = bsClear;//prBrush是打印机的Brush GetDIBSizes(thebmp[bmpindex]->Handle, BitmapInfoSize, BitmapImageSize); BitmapInfo = (PBitmapInfo) new char[BitmapInfoSize]; BitmapImage = (PChar) new char [BitmapImageSize]; GetDIB(thebmp[bmpindex]->Handle, 0, BitmapInfo, BitmapImage); DIBWidth = BitmapInfo->bmiHeader.biWidth; DIBHeight = BitmapInfo->bmiHeader.biHeight; StretchDIBits(prCan->Handle, x, y, DIBWidth*bpscale, DIBHeight*bpscale, 0, 0, DIBWidth, DIBHeight, BitmapImage, BitmapInfo, DIB_RGB_COLORS, SRCCOPY); delete BitmapImage; BitmapImage=NULL; delete BitmapInfo; BitmapInfo=NULL; } CP::~CP()//删除图像数组 { int i; for(i = 0 ; i<=nos ; i++) { delete thebmp[i]; thebmp[i]=NULL; } } 其中:thebmp[bmpindex]是TBitmap的一个数组,prCan是打印机的Printer()-> Canvas DotsPerMM = GetDeviceCaps(prCan->Handle,LOGPIXELSX)/25.399 ; PixsPermm300 = 300/25.399; bpscale = GetDeviceCaps(prCan->Handle,LOGPIXELSX)/300; 开始时nos=-1 是激光打印机