登 录
Version1:(本版本只支持保存为.bmp图片,保存为16位RGB555)
{ HDC hdcScr = GetDC(NULL); BITMAPINFOHEADER bmih; bmih.biSize = sizeof(BITMAPINFOHEADER); bmih.biWidth = GetDeviceCaps(hdcScr, HORZRES); bmih.biHeight = GetDeviceCaps(hdcScr, VERTRES); bmih.biPlanes = 1; bmih.biBitCount = 16; bmih.biCompression = BI_RGB; bmih.biSizeImage = (((bmih.biWidth * bmih.biBitCount + 31) & ~31) >> 3) * bmih.biHeight; bmih.biXPelsPerMeter = 0; bmih.biYPelsPerMeter = 0; bmih.biClrUsed = 0; bmih.biClrImportant = 0; LPBYTE lpBits = NULL; HBITMAP hDIBitmap = CreateDIBSection(NULL, (const BITMAPINFO *)&bmih, DIB_RGB_COLORS, (VOID **)&lpBits, NULL, 0); HDC hdcMem = CreateCompatibleDC(hdcScr); HGDIOBJ hOldBmp = SelectObject(hdcMem, hDIBitmap); BitBlt(hdcMem, 0, 0, bmih.biWidth, bmih.biHeight, hdcScr, 0, 0, SRCCOPY); SelectObject(hdcMem, hOldBmp); DeleteDC(hdcMem); ReleaseDC(NULL, hdcScr); BITMAPFILEHEADER bmfh; bmfh.bfType = *(WORD *)"BM"; bmfh.bfReserved1 = 0; bmfh.bfReserved2 = 0; bmfh.bfOffBits = sizeof(bmfh) + sizeof(bmih); bmfh.bfSize = bmfh.bfOffBits + bmih.biSizeImage; DWORD dwBytesWritten = 0; HANDLE hFile = CreateFile(TEXT("C://a.bmp"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(hFile, &bmfh, sizeof(bmfh), &dwBytesWritten, NULL); WriteFile(hFile, &bmih, sizeof(bmih), &dwBytesWritten, NULL); WriteFile(hFile, lpBits, bmih.biSizeImage, &dwBytesWritten, NULL); CloseHandle(hFile); DeleteObject(hDIBitmap); }
Version2: waiting...
抱歉!评论已关闭.