OpenGL绘图如何保存? DC绘图用数组就可轻松保存下来.用OpenGL的RC绘的图呢,怎么保存 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用glreadpixels读入内存,然后写出影像。 请有OpenGL方面知识的加这个群吧17385054OpenGL方面的群应该还是不多的. 再问一下,在MFC的VIEW视窗里,为视窗设置背景,用的哪个函数呢. opengl superbible里有关于将屏幕视图存成bmp格式图像的介绍。 BeginWaitCursor(); //get the client geometry CRect rect; GetClientRect(&rect); CSize size(rect.Width(), rect.Height()); TRACE("client zone:(%d;%d)\n", size.cx, size.cy); size.cx -= size.cx % 4; TRACE("final client zone:(%d;%d)\n", size.cx, size.cy); //read the bitmap data and create a bitmap FILE* fp; int NbBytes = 3 * size.cx * size.cy; unsigned char* pPixelData = new unsigned char[NbBytes]; ::glReadPixels(0, 0, size.cx, size.cy, GL_BGR_EXT, GL_UNSIGNED_BYTE, pPixelData); BITMAPINFOHEADER header; header.biWidth = size.cx; header.biHeight = size.cy; header.biSizeImage = NbBytes; header.biSize = 40; header.biPlanes = 1; header.biBitCount = 3 * 8; header.biCompression = 0; header.biXPelsPerMeter = 0; header.biYPelsPerMeter = 0; header.biClrUsed = 0; header.biClrImportant = 0; BITMAPFILEHEADER fileheader; fileheader.bfType = 'MB'; fileheader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + NbBytes; fileheader.bfReserved1 = 0; fileheader.bfReserved2 = 0; fileheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); CString strFilter = "bmp files(*.bmp)|*.bmp|all files(*.*)|*.*||"; CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strFilter, NULL); CString strPath; if (dlg.DoModal() == IDOK) { strPath = dlg.GetPathName(); ASSERT(strPath); strPath = strPath + ".bmp"; if ((fp = fopen(strPath, "wb")) == NULL) { MessageBox("can't open the file!", "error", MB_OK); return; } if (fwrite(&fileheader, 1, sizeof(BITMAPFILEHEADER), fp) < sizeof(BITMAPFILEHEADER)) { MessageBox("couldn't write the file header!", "error", MB_OK); fclose(fp); return; } if (fwrite(&header, 1, sizeof(BITMAPINFOHEADER), fp) < sizeof(BITMAPINFOHEADER)) { MessageBox("couldn't write the bitmap header!", "error", MB_OK); fclose(fp); return; } if (fwrite(pPixelData, 1, NbBytes, fp) < NbBytes) { MessageBox("couldn't write the bitmap bits!", "error", MB_OK); fclose(fp); return; } fclose(fp); } delete []pPixelData; EndWaitCursor(); 关于MFC中树控件的选中焦点问题 向大家讨教个CPU测速思想。谢谢 ! 关于Edit Control输入的问题(急) 在网页上使用ActiveX控件的问题。 帮帮忙吧 请教time_t类型的问题 如何让多个窗口获取焦点 哈哈~~~我今天终于弄到了正版的MSDN 2001 October 版!!! CSocket和Socket API哪个功能更强?可实现更多的功能? 请问如何在VC的普通窗口中使用OCX控件 找工作 怎么读PE结构,改变exe的图标呀?
OpenGL方面的群应该还是不多的.
CRect rect;
GetClientRect(&rect);
CSize size(rect.Width(), rect.Height());
TRACE("client zone:(%d;%d)\n", size.cx, size.cy); size.cx -= size.cx % 4;
TRACE("final client zone:(%d;%d)\n", size.cx, size.cy); //read the bitmap data and create a bitmap
FILE* fp; int NbBytes = 3 * size.cx * size.cy;
unsigned char* pPixelData = new unsigned char[NbBytes]; ::glReadPixels(0, 0, size.cx, size.cy, GL_BGR_EXT, GL_UNSIGNED_BYTE, pPixelData); BITMAPINFOHEADER header;
header.biWidth = size.cx;
header.biHeight = size.cy;
header.biSizeImage = NbBytes;
header.biSize = 40;
header.biPlanes = 1;
header.biBitCount = 3 * 8;
header.biCompression = 0;
header.biXPelsPerMeter = 0;
header.biYPelsPerMeter = 0;
header.biClrUsed = 0;
header.biClrImportant = 0; BITMAPFILEHEADER fileheader;
fileheader.bfType = 'MB';
fileheader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + NbBytes;
fileheader.bfReserved1 = 0;
fileheader.bfReserved2 = 0;
fileheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); CString strFilter = "bmp files(*.bmp)|*.bmp|all files(*.*)|*.*||";
CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strFilter, NULL);
CString strPath;
if (dlg.DoModal() == IDOK)
{
strPath = dlg.GetPathName(); ASSERT(strPath);
strPath = strPath + ".bmp";
if ((fp = fopen(strPath, "wb")) == NULL)
{
MessageBox("can't open the file!", "error", MB_OK);
return;
} if (fwrite(&fileheader, 1, sizeof(BITMAPFILEHEADER), fp) < sizeof(BITMAPFILEHEADER))
{
MessageBox("couldn't write the file header!", "error", MB_OK);
fclose(fp);
return;
} if (fwrite(&header, 1, sizeof(BITMAPINFOHEADER), fp) < sizeof(BITMAPINFOHEADER))
{
MessageBox("couldn't write the bitmap header!", "error", MB_OK);
fclose(fp);
return;
} if (fwrite(pPixelData, 1, NbBytes, fp) < NbBytes)
{
MessageBox("couldn't write the bitmap bits!", "error", MB_OK);
fclose(fp);
return;
}
fclose(fp);
}
delete []pPixelData; EndWaitCursor();