//Выводим BMP на экран - pDC
CDC mdcPicture;
BITMAP bmpProperties;
HBITMAP bmpHandle;
CBitmap *bmpFromHandle;
CBitmap bmpPicture;
bmpHandle = (HBITMAP)LoadImage(NULL,"C:\\TH.BMP",IMAGE_BITMAP,0, 0, LR_LOADFROMFILE);
// Convert the Win32 bitmap handle into an MFC bitmap object
bmpFromHandle = bmpPicture.FromHandle(bmpHandle);
bmpPicture.Attach(bmpHandle);
// Call the Win32 GetObject() function to get the properties
// of the bitmap and store them in a BITMAP structure
::GetObject(bmpPicture, sizeof(bmpProperties), &bmpProperties);
// Create a compatible device context
mdcPicture.CreateCompatibleDC(pDC);
// Select the bitmap into the device context
CBitmap* bmpPrevious = mdcPicture.SelectObject(bmpFromHandle);
pDC->BitBlt(0, 0, bmpProperties.bmWidth, bmpProperties.bmHeight, &mdcPicture, 0, 0, SRCCOPY);
//Рисуем на pDC экране прямую
pDC->MoveTo(100, 100);
pDC->LineTo(200, 200);
//Сохраняем BMP c прямой
BITMAPINFO bmpinfo;
LPVOID pBits;
CDC hdc2;
DWORD dwWidth, dwHeight, dwBPP, dwNumColors;
HGDIOBJ gdiobj;
HANDLE hfile;
DWORD dwBytes;
dwBPP = pDC->GetDeviceCaps(BITSPIXEL);
dwNumColors = 0;
dwWidth = 768;
dwHeight = 576;
hdc2.CreateCompatibleDC(pDC);
bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpinfo.bmiHeader.biWidth = dwWidth;
bmpinfo.bmiHeader.biHeight = dwHeight;
bmpinfo.bmiHeader.biPlanes = 1;
bmpinfo.bmiHeader.biBitCount = (WORD) dwBPP;
bmpinfo.bmiHeader.biCompression = BI_RGB;
bmpinfo.bmiHeader.biSizeImage = 0;
bmpinfo.bmiHeader.biXPelsPerMeter = 0;
bmpinfo.bmiHeader.biYPelsPerMeter = 0;
bmpinfo.bmiHeader.biClrUsed = 0;
bmpinfo.bmiHeader.biClrImportant = 0;
bmpHandle = CreateDIBSection(*pDC, &bmpinfo, DIB_RGB_COLORS, &pBits, NULL, 0);
gdiobj = SelectObject(hdc2, (HGDIOBJ)bmpHandle);
RGBQUAD colors[256];
BITMAPFILEHEADER bitmapfileheader;
BITMAPINFOHEADER bitmapinfoheader;
bitmapfileheader.bfType = 0x4D42;
bitmapfileheader.bfSize = ((dwWidth * dwHeight * dwBPP)/8) + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (dwNumColors * sizeof(RGBQUAD));
bitmapfileheader.bfReserved1 = 0;
bitmapfileheader.bfReserved2 = 0;
bitmapfileheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (dwNumColors * sizeof(RGBQUAD));
bitmapinfoheader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfoheader.biWidth = dwWidth;
bitmapinfoheader.biHeight = dwHeight;
bitmapinfoheader.biPlanes = 1;
bitmapinfoheader.biBitCount = (WORD)dwBPP;
bitmapinfoheader.biCompression = BI_RGB;
bitmapinfoheader.biSizeImage = 0;
bitmapinfoheader.biXPelsPerMeter = 0;
bitmapinfoheader.biYPelsPerMeter = 0;
bitmapinfoheader.biClrUsed = dwNumColors;
bitmapinfoheader.biClrImportant = 0;
hfile = CreateFile(szBMPFileName,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
WriteFile(hfile,&bitmapfileheader,sizeof(BITMAPFILEHEADER), &dwBytes,NULL);
WriteFile(hfile,&bitmapinfoheader,sizeof(BITMAPINFOHEADER), &dwBytes,NULL);
WriteFile(hfile,pBits,(dwWidth*dwHeight*dwBPP)/8,&dwBytes,NULL);
CloseHandle(hfile);
hdc2.DeleteDC();
Преобразования BMP файла
Как у меня сделано.
Код:
А мне как-нибудь, чтоб без контекста дисплея обходится? пасиба большое!
Цитата:
hdc - If this handle is NULL, the function creates a memory device context compatible with the application's current screen.
пасиба большое! буду искать свет))