这个函数是别人写的,是把界面的图像文件数据存到缓冲区当中然后读出来,我现在想自己存但是不行.
#define WORD LineType 
void CDemo_VCDlg::PictToBuff(CDC *dc, LineType *PictBuf,WORD PictWidth, WORD PictHeight,WORD Width,WORD Height,BYTE Color)
{
int x,y,z,EndX,EndY,vC;
WORD v,vx;
WORD _ROLE[]={0x8000,0x4000,0x2000,0x1000,0x0800,0x0400,0x0200,0x0100,
 0x0080,0x0040,0x0020,0x0010,0x0008,0x0004,0x0002,0x0001}; // 先清除缓冲区
for (x=0;x<128;++x)
for (y=0;y<511;++y) PictBuf[y][x] = 0; // 根据图片和屏体的宽高决定截取图片的宽高,保证数据不越界
if (PictWidth>Width)   EndX=Width;  else EndX=PictWidth;
if (PictHeight>Height) EndY=Height; else EndY=PictHeight; // 遍历高度和宽度
    // 先截取红色
for (y=0;y<EndY;++y)
for (x=0;x<(EndX+15)/16;++x)
{
v=0;
for (z=0;z<16;++z)
{
vC = dc->GetPixel(x*16+z,y);
if ((vC & RGB(0xff,0,0))>RGB(0x80,0,0)) v |= _ROLE[z];
}
vx = (v>>8) + ((v&0xff)<<8);
PictBuf[y][x] = vx;
}
    // 双色屏再截取绿色
if (Color!=0)
{
for (y=0;y<EndY;++y)
for (x=0;x<(EndX+15)/16;++x)
{
v=0;
for (z=0;z<16;++z)
{
vC = dc->GetPixel(x*16+z,y);
if ((vC & RGB(0,0xff,0))>RGB(0,0x80,0)) v |= _ROLE[z];
}
vx = (v>>8) + ((v&0xff)<<8);
PictBuf[y+Height][x] = vx;
}
}
}
下面是别人源代码的上面把界面图像处理的一个例子:m_Pict.GetWindowRect(&rect);
PictToBuff(m_Pict.GetDC(),SendBuf,rect.right-rect.left,rect.bottom-rect.top,LedWidth,LedHeight,LedColor); 而我自己想通过打开一个bmp文件然后把数据送到缓冲区,代码如下:CString m_sBitmap;
char szFileter[]="Bitmap Files (*.bmp)|*.bmp||";CFileDialog m_ldFileTRUE,".bmp","*.bmp",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFileter);
m_ldFile.DoModal();
m_sBitmap=m_ldFile.GetPathName();
UpdateData(FALSE);
HBITMAP hBitmap=(HBITMAP) ::LoadImage(AfxGetInstanceHandle(),m_sBitmap,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);然后调用PictToBuff(hBitmapSendBuf,rect.right-rect.left,rect.bottom-rect.top,LedWidth,LedHeight,LedColor);
行不通,不知道为什么了.下面是错误代码:
error C2664: 'PictToBuff' : cannot convert parameter 1 from 'struct HBITMAP__ *' to 'class CDC *'