高手帮我改下程序啊
下面的代码不能保存256色图.
var
dibH : hBitmap;
bits : pointer;
info : PBITMAPINFO;
width,height : integer;
screenDC,dibDC : hDC;
f : file of byte;
BFH:BITMAPFILEHEADER;
BIH:TBITMAPINFOHEADER;
nBitCount,nBytesPerline,nSize,nNumColors,dwBmiSize:Integer;
ColorTab:array[0..255]of TRGBQUAD;
bm:BITMAP;
begin
//screenDC := getDC(getDeskTopWindow);
nNumColors:=0;
nBitCount:=8;
screenDC := getDC(0);
dibDC := createCompatibleDC(screenDC);
width := getDeviceCaps(screenDC,HORZRES);
height := getDeviceCaps(screenDC,VERTRES);
nBytesPerline:=((width*nBitCount+31)div 32)*4;
if nBitCount >8 then nNumColors:=0
else nNumColors:=(1 shl nBitCount);
dwBmiSize:=40+nNumColors*4;
nSize:=nBytesPerline*height;
zeromemory(@BIH,sizeOf(BIH));
BIH.biSize:=40;
BIH.biPlanes:=1;
BIH.biWidth:=width;
BIH.biHeight:=height;
BIH.biBitCount:=nBitCount;
GetMem(info,40+4*nNumColors);
zeromemory(Info,40+4*nNumColors);
move(BIH,info^,40); // PBITMAPINFO结构不是很清楚,感觉这里有问题
dibH:=createDIBSection(dibDC,info^,DIB_RGB_COLORS,bits,0,0);
selectObject(dibDC,dibH);
bitblt(dibDC,0,0,width,height,screenDC,0,0,SRCCOPY);
releaseDC(getDeskTopWindow,screenDC);
assignFile(f,shot);
reWrite(f);
zeromemory(@BFH,sizeOf(BFH));
zeromemory(@ColorTab,sizeOf(ColorTab));
BFH.bfType:=ord('B')+(ord('M')shl 8);
BFH.bfSize:=14+dwBmiSize+nSize;
BFH.bfOffBits:=14+40+nNumColors;
blockWrite(f,BFH,sizeof(BITMAPFILEHEADER));
blockWrite(f,BIH,40);
if nBitCount <=8 then begin
GetDIBColorTable(dibDC,0,nNumColors,ColorTab);
blockWrite(f,ColorTab,nNumColors);//调色板数据怎么存????
end;
blockWrite(f,bits^,nSize);
closeFile(f);
deleteObject(dibH);
deleteDC(dibDC);
end;