救急:一段打印BMP位图的代码,昨天琢磨不一天无进展,肯请大伙帮帮忙 分不是问题
int __stdcall PrintBmpFile(char *FileName,int x,int y,int PrintType)
{
PDIB pdib;
int iWhite,iBlack,i,j,iLineLength,JumpByte,iSpilthBit,ReturnValue,itemp;
LPVOID pHeader,pCurrent,pMove;
pdib=DibOpenFile(FileName);
if(pdib==NULL)
return 100;
//这时候pCurrent和pHeader指的是位图数据的地址
pCurrent=pHeader=(LPBYTE)(pdib)+(int)pdib->biSize;
if(pdib->biClrUsed==0) //颜色数为2 的biBitCount次方
{
问题:iBlack和iWhite是做什么的?
iBlack=0x00000000;
iWhite=0x00ffffff;
}
else
for(i=0,j=0;i<(int)pdib->biClrUsed ;i++)
{
问题:这个条件语句的意义是什么?
if((*((LPBYTE)pCurrent)==0x00)&&
(*((LPBYTE)pCurrent+1)==0x00)&&
(*((LPBYTE)pCurrent+2)==0x00)&&
(*((LPBYTE)pCurrent+3)==0x00))
{
问题: iBlack 是怎么一个值?
iBlack=((LPBYTE)pCurrent-(LPBYTE)pHeader)/4;
j=j+1;
}
else
问题:这个条件语句的意义是什么?
if((*((LPBYTE)pCurrent)==0xFF)&&
(*((LPBYTE)pCurrent+1)==0xFF)&&
(*((LPBYTE)pCurrent+2)==0xFF)&&
(*((LPBYTE)pCurrent+3)==0x00))
{
iWhite=((LPBYTE)pCurrent-(LPBYTE)pHeader)/4;
j=j+1;
}
pCurrent=(LPBYTE)pCurrent+4;
问题:比如为什么J=2就跳出for循环
if(j==2)
break;
}
问题:iLineLength代表是一行的位数么?
iLineLength=pdib->biWidth *(pdib->biBitCount )/8;
if((((pdib->biWidth )*(pdib->biBitCount ))%8)!=0)
iLineLength++;
问题: JumpBytei和SpilthBit,不知怎样得来
JumpByte=(pdib->biWidth *pdib->biBitCount )%32;
if(JumpByte)
JumpByte=(32-JumpByte)/8;
iSpilthBit=8-(pdib->biWidth)%8;
if(iSpilthBit==8)
iSpilthBit=0;
问题:biClrUsed==0时为什么 不要加(int)(pdib->biClrUsed*4)?
问题:pCurrent,pMove的意义
if(pdib->biClrUsed==0)
pCurrent=pMove=pHeader=(LPBYTE)pHeader;
else
pCurrent=pMove=pHeader=(LPBYTE)pHeader+(int)(pdib->biClrUsed*4);
if(JumpByte)
for(i=0;i<pdib->biHeight -1;i++)
{
pCurrent=(LPBYTE)pCurrent+iLineLength;
pMove=(LPBYTE)pMove+iLineLength+JumpByte;
memcpy((LPBYTE)pCurrent,(LPBYTE)pMove,iLineLength);
}
unsigned char ucTemp;
问题:后面的也请指教。
switch(pdib->biBitCount )
{
case COLOR_MONOCHROME:
break;
case COLOR_16:
iLineLength=Change16Color_MonochromeColor(
pdib,
(LPBYTE)pHeader,
iLineLength,
iWhite,
iBlack);
break;
case COLOR_256:
iLineLength=Change256Color_MonochromeColor(
pdib,
(LPBYTE)pHeader,
iLineLength,
iWhite,
iBlack);
break;
case COLOR_TRUE:
iLineLength=ChangeTrueColor_MonochromeColor(
pdib,
(LPBYTE)pHeader,
iLineLength);
break;
default:
break;
}
if(iWhite!=0)
{
for(i=0;i<pdib->biHeight;i++)
for(j=0;j<iLineLength;j++)
{
ucTemp=*((LPBYTE)pHeader+i*iLineLength+j);
ucTemp=~ucTemp;
if(j==iLineLength-1)
{
ucTemp=ChangeSpilthBit(iSpilthBit,ucTemp);
}
*((LPBYTE)pHeader+i*iLineLength+j)=ucTemp;
}
}
for(i=0;i<(pdib->biHeight )/2;i++)
{
for(j=0;j<iLineLength;j++)
{
ucTemp=*((LPBYTE)pHeader+i*iLineLength+j);
*((LPBYTE)pHeader+i*iLineLength+j)=*((LPBYTE)pHeader+(pdib->biHeight-i-1)*iLineLength+j);
*((LPBYTE)pHeader+(pdib->biHeight-i-1)*iLineLength+j)=ucTemp;
}
}
char HeaderCommand[200000]={0};
char X_coordinate[5],Y_coordinate[5],Temp_Height[5],Temp_Length[5];
int BufferLen;
itoa(x,X_coordinate,10);
itoa(y,Y_coordinate,10);
if(PrintType==0)
{
if(pdib->biHeight %8)
itemp=(pdib->biHeight/8)+1;
else
itemp=pdib->biHeight/8;
if(!ArrayTransform((LPBYTE)pHeader,pdib->biHeight,iLineLength))
{
GlobalFreePtr(pdib);
return 100;
}
itoa(pdib->biHeight ,Temp_Length,10);
itoa(iLineLength*8,Temp_Height,10);
BufferLen=iLineLength*8*itemp;
}
else
{
//Disable by wqz 2001/07/19
//itoa(iLineLength,Temp_Length,10);
//add by wqz 2001/07/19
itoa(iLineLength*8,Temp_Length,10);
itoa(pdib->biHeight,Temp_Height,10);
BufferLen=pdib->biHeight*iLineLength;
}
//Add by wqz 2001/07/18
wsprintf(HeaderCommand,"IBN %s %s %s %s ",
X_coordinate,Y_coordinate,
Temp_Length,Temp_Height);
//BufferLen=nTemp_Width*nHeight;
int nTemp_BufferLen=strlen(HeaderCommand);
memcpy(HeaderCommand+strlen(HeaderCommand),(LPBYTE)pHeader+2,BufferLen);
BufferLen=nTemp_BufferLen+BufferLen;
///for test
ReturnValue=SendPrintCommand(HeaderCommand,BufferLen,1000);
GlobalFreePtr(pdib);
return ReturnValue;
}
问题1: iWhite, iBlack, iLineLength, jumpByte, iSpilthBit分别代表什么意义?
问题2:请见代码处问题。
谢谢!!!
问题点数:100、回复次数:9Top
1 楼lovenoend(有容乃大)回复于 2004-09-03 17:02:27 得分 0
沉底了,顶上Top
2 楼54783szg(百里洲)回复于 2004-09-03 17:08:04 得分 100
有EMAIL吗?我给你发个例子!Top
3 楼RedSunIT(精彩每一天)回复于 2004-09-06 08:32:56 得分 0
To: 54783szg(浪淘沙)
有啊:
wwb81@sohu.com 或 Sam8110@126.com
谢谢!!!Top
4 楼54783szg(百里洲)回复于 2004-09-06 09:41:24 得分 0
To:RedSunIT:邮件已发出,请查收Top
5 楼RedSunIT(精彩每一天)回复于 2004-09-06 10:16:11 得分 0
To: 54783szg(浪淘沙)
你的邮件已收到, 看看先, 衷心谢谢, 当然,分也是少不了的。
不过还是希望有人帮我解释一下上面的代码:)Top
6 楼cntwsoft(飓风中心)回复于 2004-09-06 10:44:23 得分 0
upTop
7 楼weakwater(我是河南人)回复于 2004-09-06 17:55:43 得分 0
帮你UPTop
8 楼RedSunIT(精彩每一天)回复于 2004-09-08 14:30:48 得分 0
结帖,谢了 54783szg(浪淘沙) 先Top
9 楼UT_Flex(Flex)回复于 2004-11-04 12:00:27 得分 0
能给我一份吗?
flqh@21cn.com
谢先!Top




