// Fill in the color table from DIBSection if( lpbmi->bmiHeader.biBitCount <= 8 ) GetDIBColorTable( hSourceDC, 0, 1 << lpbmi->bmiHeader.biBitCount, lpbmi->bmiColors );
// Clean up and delete the DCs SelectObject( hSourceDC, hOldSourceBitmap ); DeleteDC( hSourceDC ); ReleaseDC( NULL, hDC ); GlobalUnlock(hNewDIB);
等待高手
FILE* fp=fopen("c:\\favicon.ico","rb");
int n=0;
if(fp)
{
fseek(fp,0,SEEK_END);
LONG lLen=ftell(fp);
char* str=new char[lLen*2+1];
strset(str,0);
rewind(fp);
while(fread(&b,1,1,fp)>0)
{
n+=sprintf(c+n,"%02x",b);
}
fclose(fp);
}
BYTE b;
FILE* fp=fopen("c:\\favicon.ico","rb");
int n=0;
if(fp)
{
fseek(fp,0,SEEK_END);
LONG lLen=ftell(fp);
char* str=new char[lLen*2+1];
strset(str,0);
rewind(fp);
while(fread(&b,1,1,fp)>0)
{
n+=sprintf(str+n,"%02x",b);
}
fclose(fp);
}
大约就是这个鸟样子了
不知道为什么要转成字符串再分析
hFile.Open(_T("C:\\1.bmp"),CFile::modeRead);
if(!hFile)return;
long dwSize = hFile.GetLength() ; //得到图片的长度BITMAPFILEHEADER bfhHeader;
hFile.Read(&bfhHeader,sizeof(BITMAPFILEHEADER));
if(bfhHeader.bfType !=((WORD)('M'<<8)|'B')){// || bfhHeader.bfSize != dwSize) {
::MessageBox(NULL,_T("The BMP file header error!"),_T("warning"),MB_OK);
return;
}
if(bfhHeader.bfSize != dwSize)
{
::MessageBox(NULL,_T("The BMP file size error!"),_T("warning"),MB_OK);
return;
}
UINT uBmpInfoLen = (UINT)bfhHeader.bfOffBits - sizeof(BITMAPFILEHEADER);
LPBITMAPINFO lpBitmap = (LPBITMAPINFO)new BYTE[uBmpInfoLen];
hFile.Read((LPVOID)lpBitmap,uBmpInfoLen);if((* (LPDWORD)(lpBitmap))!=sizeof(BITMAPINFOHEADER))
{
::MessageBox(NULL,"The BMP is not Windows 3.0 format!","warning",MB_OK);
return;
} DWORD dwBitlen = bfhHeader.bfSize - bfhHeader.bfOffBits; CDC *pDC = GetDC();
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);LPBYTE lpBits;
HBITMAP hBmp=::CreateDIBSection(dcMem.m_hDC,lpBitmap,DIB_RGB_COLORS,(void**)&lpBits,NULL,0);
hFile.Read(lpBits,dwBitlen);CBitmap BmpImg;
BmpImg.Attach(hBmp);
dcMem.SelectObject(&BmpImg);
pDC->BitBlt(0,0,1000,1000,&dcMem,0,0,SRCCOPY);delete lpBitmap;
ReleaseDC(&dcMem);
ReleaseDC(pDC);
DeleteObject(&BmpImg);
hFile.Close() ;
并不理其中的格式,楼主如果你的问题解决了,麻烦共享一下哦,谢谢qq269632015 email:[email protected]
{
HDC hDC = NULL, hSourceDC;
HBITMAP hOldSourceBitmap;
HANDLE hNewDIB;
LPBITMAPINFO lpbmi = NULL;
DWORD dwSize;
DIBSECTION ds;
DWORD dwColorNum; // get DIB info
GetObject(hBitmap, sizeof(DIBSECTION), &ds);
dwColorNum = ds.dsBmih.biClrUsed;
if (dwColorNum == 0 && ds.dsBmih.biBitCount <= 8)
dwColorNum = 1 << ds.dsBmih.biBitCount; // Allocate and fill out a BITMAPINFO struct for the new DIB
dwSize = sizeof(BITMAPINFOHEADER) + (dwColorNum * sizeof(RGBQUAD)) + ds.dsBmih.biSizeImage;
hNewDIB = GlobalAlloc(GHND, dwSize);
if (! hNewDIB)
return NULL;
lpbmi = (LPBITMAPINFO)GlobalLock(hNewDIB);
if (! lpbmi)
return NULL;
lpbmi->bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
lpbmi->bmiHeader.biWidth = ds.dsBm.bmWidth;
lpbmi->bmiHeader.biHeight = ds.dsBm.bmHeight;
lpbmi->bmiHeader.biPlanes = 1;
lpbmi->bmiHeader.biBitCount = ds.dsBmih.biBitCount;
lpbmi->bmiHeader.biCompression = ds.dsBmih.biCompression;
lpbmi->bmiHeader.biSizeImage = ds.dsBmih.biSizeImage;
lpbmi->bmiHeader.biXPelsPerMeter = ds.dsBmih.biXPelsPerMeter;
lpbmi->bmiHeader.biYPelsPerMeter = ds.dsBmih.biYPelsPerMeter;
lpbmi->bmiHeader.biClrUsed = ds.dsBmih.biClrUsed;
lpbmi->bmiHeader.biClrImportant = ds.dsBmih.biClrImportant; // get DC for operation
hDC = GetDC( NULL );
// get DIB bits
if (! GetDIBits(hDC,
hBitmap,
0L,
(DWORD)ds.dsBm.bmHeight,
(LPBYTE)lpbmi + (WORD)lpbmi->bmiHeader.biSize + (dwColorNum*sizeof(RGBQUAD)),
(LPBITMAPINFO)lpbmi,
(DWORD)DIB_RGB_COLORS))
{
GlobalUnlock(hNewDIB);
ReleaseDC(NULL,hDC);
return NULL;
} // memory DC
hSourceDC = CreateCompatibleDC( hDC );
// Select DIBSections into DCs
hOldSourceBitmap = (HBITMAP)SelectObject( hSourceDC, hBitmap );
// Fill in the color table from DIBSection
if( lpbmi->bmiHeader.biBitCount <= 8 )
GetDIBColorTable( hSourceDC, 0, 1 << lpbmi->bmiHeader.biBitCount, lpbmi->bmiColors );
// Clean up and delete the DCs
SelectObject( hSourceDC, hOldSourceBitmap );
DeleteDC( hSourceDC );
ReleaseDC( NULL, hDC );
GlobalUnlock(hNewDIB);
return hNewDIB;
}
CBitmap::GetBitmapBits
DWORD GetBitmapBits(
DWORD dwCount,
LPVOID lpBits
) const
将位图数据读到lpBits中,另外SDK中也有相关的API,好像是:GetBitmapBits。具体用法你查一下MSDN