一个超弱的问题!--显示一个256色位图。 看看这一页,好好找找:http://www.csdn.net/dev/Visual%20C++/source%20code/Bitmap/index.htm 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 www.vckbase.com的vc知识库中有解决方案和例子程序 //在pDC 中显示任意颜色的位图BOOL BmpRead(CDC *pDC,char *FileName,int x,int y){ int width,height; BITMAPINFOHEADER bi; int dwOffset; int i; CFile OpenFile; LOGPALETTE *lp; BYTE PaletteBuffer[1024]; CPalette cp,*OldCp; BYTE *pBuf; BITMAPINFO *bf; if(OpenFile.Open (FileName,CFile::modeRead)==NULL)return FALSE; OpenFile.Seek(14,CFile::begin); OpenFile.Read(&bi,40); width=bi.biWidth; height=bi,biHeight; if(bi.biSizeImage==0)bi.biSizeImage=(long)bi.biWidth*bi.biHeight*bi.biBitCount/8; if(bi.biBitCount<=8) { lp =(LOGPALETTE *)new BYTE[sizeof(LOGPALETTE) +(int)bi.biClrUsed* sizeof(PALETTEENTRY)]; lp->palVersion=0x300; lp->palNumEntries=(int)bi.biClrUsed; OpenFile.Read(PaletteBuffer,(int)bi.biClrUsed*4); OpenFile.Close(); for (i = 0; i < (int)bi.biClrUsed; i++){ lp->palPalEntry[i].peRed = PaletteBuffer[4*i+2]; lp->palPalEntry[i].peGreen = PaletteBuffer[4*i+1]; lp->palPalEntry[i].peBlue = PaletteBuffer[4*i+0]; lp->palPalEntry[i].peFlags = 0; } cp.CreatePalette(lp); OldCp=pDC->SelectPalette(&cp,FALSE); pDC->RealizePalette(); } else OpenFile.Close(); if(bi.biBitCount<=8) bf=(BITMAPINFO*)new BYTE[bi.biSize + bi.biClrUsed *4]; else bf=(BITMAPINFO*)new BYTE[bi.biSize]; OpenFile.Open (FileName, CFile::modeRead); OpenFile.Seek(14,CFile::begin); if(bi.biBitCount<=8) OpenFile.Read(bf,(int)bi.biClrUsed *4+bi.biSize); else OpenFile.Read(bf,bi.biSize); OpenFile.Close(); pBuf=new BYTE[bi.biSizeImage]; OpenFile.Open(FileName,CFile::modeRead); if(bi.biBitCount<=8) dwOffset=54+bi.biClrUsed*4; else dwOffset=54; OpenFile.Seek(dwOffset,CFile::begin); OpenFile.Read(pBuf,bi.biSizeImage); OpenFile.Close(); x=x+(width-(int)bi.biWidth)/2; y=y+(height-(int)bi.biHeight)/2; StretchDIBits( pDC->m_hDC, // handle to device context 0, // x-coordinate of upper-left corner of dest. rectangle 0, // y-coordinate of upper-left corner of dest. rectangle width, // width of destination rectangle height, // height of destination rectangle 0, // x-coordinate of upper-left corner of source rectangle 0, // y-coordinate of upper-left corner of source rectangle bi.biWidth, // width of source rectangle bi.biHeight, // height of source rectangle pBuf, // address of bitmap bits (BITMAPINFO *)bf, // address of bitmap data DIB_RGB_COLORS, // usage flags SRCCOPY // raster operation code );pDC->TextOut(0,0,ts); if(bi.biBitCount<=8){ pDC->SelectPalette(OldCp,FALSE); cp.DeleteObject(); delete lp; } delete pBuf; delete bf; return TRUE;} pDC->TextOut(0,0,ts); 该行毫无价值,应该删除 不然再加上在Microsoft.com的KnowLeage上有loadpic.exe 问题: define的值为何不能比较 DirectShow,想把窗口一static作为视频窗口,在IVideoWindow->put_Owner失败~可能是什么原因? 有哪位兄弟写过VPN拨号器之类的程序的? 在新开的线程中如何使用类中的成员变量和成员函数? 最小窗口如何设定 感觉现在用.NET的人好少? 我的问题问了N次没有人回答?UP的人也好少!郁闷! 如何获取系统的日历时间 怎样让我的程序总在最上方(总在前面)? 十万火急:怎样建立一个能屏蔽所有操作的应用程序?(WINNT) 关于编写WINDOWS NT驱动的问题 学COM用什么书 activex的鼠标和键盘事件
BOOL BmpRead(CDC *pDC,char *FileName,int x,int y)
{
int width,height;
BITMAPINFOHEADER bi;
int dwOffset;
int i;
CFile OpenFile;
LOGPALETTE *lp;
BYTE PaletteBuffer[1024];
CPalette cp,*OldCp;
BYTE *pBuf;
BITMAPINFO *bf;
if(OpenFile.Open (FileName,CFile::modeRead)==NULL)return FALSE;
OpenFile.Seek(14,CFile::begin);
OpenFile.Read(&bi,40);
width=bi.biWidth;
height=bi,biHeight;
if(bi.biSizeImage==0)bi.biSizeImage=(long)bi.biWidth*bi.biHeight*bi.biBitCount/8;
if(bi.biBitCount<=8)
{
lp =(LOGPALETTE *)new BYTE[sizeof(LOGPALETTE) +(int)bi.biClrUsed* sizeof(PALETTEENTRY)];
lp->palVersion=0x300;
lp->palNumEntries=(int)bi.biClrUsed;
OpenFile.Read(PaletteBuffer,(int)bi.biClrUsed*4);
OpenFile.Close();
for (i = 0; i < (int)bi.biClrUsed; i++){
lp->palPalEntry[i].peRed = PaletteBuffer[4*i+2];
lp->palPalEntry[i].peGreen = PaletteBuffer[4*i+1];
lp->palPalEntry[i].peBlue = PaletteBuffer[4*i+0];
lp->palPalEntry[i].peFlags = 0;
}
cp.CreatePalette(lp);
OldCp=pDC->SelectPalette(&cp,FALSE);
pDC->RealizePalette();
}
else
OpenFile.Close();
if(bi.biBitCount<=8)
bf=(BITMAPINFO*)new BYTE[bi.biSize + bi.biClrUsed *4];
else
bf=(BITMAPINFO*)new BYTE[bi.biSize];
OpenFile.Open (FileName, CFile::modeRead);
OpenFile.Seek(14,CFile::begin);
if(bi.biBitCount<=8)
OpenFile.Read(bf,(int)bi.biClrUsed *4+bi.biSize);
else
OpenFile.Read(bf,bi.biSize);
OpenFile.Close(); pBuf=new BYTE[bi.biSizeImage]; OpenFile.Open(FileName,CFile::modeRead);
if(bi.biBitCount<=8)
dwOffset=54+bi.biClrUsed*4;
else
dwOffset=54;
OpenFile.Seek(dwOffset,CFile::begin);
OpenFile.Read(pBuf,bi.biSizeImage);
OpenFile.Close(); x=x+(width-(int)bi.biWidth)/2;
y=y+(height-(int)bi.biHeight)/2;
StretchDIBits(
pDC->m_hDC, // handle to device context
0, // x-coordinate of upper-left corner of dest. rectangle
0, // y-coordinate of upper-left corner of dest. rectangle
width, // width of destination rectangle
height, // height of destination rectangle
0, // x-coordinate of upper-left corner of source rectangle
0, // y-coordinate of upper-left corner of source rectangle
bi.biWidth, // width of source rectangle
bi.biHeight, // height of source rectangle
pBuf, // address of bitmap bits
(BITMAPINFO *)bf, // address of bitmap data
DIB_RGB_COLORS, // usage flags
SRCCOPY // raster operation code
);
pDC->TextOut(0,0,ts);
if(bi.biBitCount<=8)
{
pDC->SelectPalette(OldCp,FALSE);
cp.DeleteObject();
delete lp;
}
delete pBuf;
delete bf;
return TRUE;
}