在VC 6.0中,写一个读取bmp位图文件的程序,输出文件的高和宽,同时在位图中留下你修改过的痕迹—如在图中加入一条白色的线段等。
解决方案 »
- vs2005编译结束时没有执行Application_BuildFinish(ByVal numError, ByVal numWarning)宏函数
- 硬件设备功率。。。
- 菜单问题
- 如何保持对话框在全屏游戏中显示?
- 如何将CListView中的CListCtrl重载为一个已经写好的CListCtrl??
- 如何在COM中增加一个Timer?
- 求助CTreeCtrl问题
- 有什么办法可以判断数据库中是否存在某表?
- 请问我如果要在程序中实现简单的二维矢量作图功能
- 高手赐教!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- socket编程触发接收问题....望高手帮帮忙!!!!!!!!!!!
- 我写了一个DLL但是调用时老报错,提示内存不能为读!!!!!!!在线等
BIMTAP bmp;
GetObject(hBitmap, sizeof(BITMAP), &bmp);// Get the width and height of the bitmap
int nWidth = bmp.bmWidth;
int nHeight = bmp.bmHeight;// Add a line in the center of the bitmap
HDC hdc = GetDC(NULL);
HDC memdc = CreateCompatibleDC(hdc);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(memdc, hBitmap);
SelectObject(memdc, hOldBitmap);HPEN hPen = CreatePen(PS_SOLID, 1, RGB(255,255,255));
HPEN hOldPen = (HPEN)SelectObject(memdc, hPen);
MoveTo(memdc, 0, nHeight/2);
LineTo(memdc, nWidth, nHeight/2);
SelectObject(memdc, hOldPen);ReleaseDC(NULL, hdc);
DeleteDC(memdc);
Note: insert the code between SelectObject(memdc, hOldPen) and ReleaseDC(NULL, hdc);
=============================================================== PBITMAPINFO pbmi;
WORD nClrBits; nClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel); if (nClrBits < 24)
{
pbmi = (PBITMAPINFO)::LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER) +
sizeof(RGBQUAD) * (1<<nClrBits));
}
else
{
pbmi = (PBITMAPINFO)::LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER));
} pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = bmp.bmWidth;
pbmi->bmiHeader.biHeight = bmp.bmHeight;
pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
if (nClrBits < 24)
pbmi->bmiHeader.biClrUsed = (1 << nClrBits); pbmi->bmiHeader.biCompression = BI_RGB; pbmi->bmiHeader.biSizeImage = ( (bmp.bmWidth * nClrBits + 31) & ~31 ) / 8 * bmp.bmHeight;
pbmi->bmiHeader.biClrImportant = 0; HANDLE hf; // file handle
BITMAPFILEHEADER hdr; // bitmap file-header
PBITMAPINFOHEADER pbih; // bitmap info-header LPBYTE lpBits; // memory pointer
DWORD dwTmp; pbih = (PBITMAPINFOHEADER)pbmi;
lpBits = (LPBYTE)::GlobalAlloc(GMEM_FIXED, pbih->biSizeImage); if (!lpBits)
{
TRACE("Memory space is not enough to create bitmap!\n");
return;
} if (!GetDIBits(memdc, hBitmap, 0, pbih->biHeight, lpBits, pbmi, DIB_RGB_COLORS))
{
TRACE("Fail to retrieve the bits of the specified bitmap!\n");
return;
}// pszFile is file name what you want to save
hf = ::CreateFile(pszFile, GENERIC_READ | GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL);
hdr.bfType = 0x4d42; // 0x4d = 'M', 0x42 = 'B'
hdr.bfSize = sizeof(BITMAPFILEHEADER) + pbih->biSizeImage + pbih->biClrUsed * sizeof(RGBQUAD);
hdr.bfOffBits = sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD);
// bitmap file-header
WriteFile(hf, &hdr, sizeof(BITMAPFILEHEADER), &dwTmp, NULL);
// bitmap info-header
WriteFile(hf, pbih, pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD), &dwTmp, NULL);
// the array of color indicates into .BMP file.
WriteFile(hf, lpBits, pbih->biSizeImage, &dwTmp, NULL); ::CloseHandle(hf); // Free memory
::GlobalFree((HGLOBAL)lpBits);
file,ok? I will thanks again.
http://www.geekclaw.com/changebitmap.rar
http://code.knowsky.com/down/5626.html
错误如下:1.c:\documents and settings\owner\my documents\my qq files\changebitmap.cpp(100) : error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'long (struct HWND__ *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(struct HWND__ *,unsigned
2.c:\documents and settings\administrator\桌面\新建文件夹\changebitmap1.cpp(5) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
执行 cl.exe 时出错.