高手帮我改下程序啊

book_reinforce 2008-05-14 04:34:50
下面的代码不能保存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;
...全文
73 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
book_reinforce 2008-05-14
  • 打赏
  • 举报
回复
他这个也不支持8位
skylkj 2008-05-14
  • 打赏
  • 举报
回复
屏幕截图?
转一篇
http://hi.baidu.com/adson/blog/item/38f73cfaaa43d78d9f5146e7.html

16,742

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧