int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
    UINT  num = ;          // number of image encoders
    UINT  size = ;         // size of the image encoder array in bytes

    ImageCodecInfo* pImageCodecInfo = NULL;

    GetImageEncodersSize(&num, &size);
    )
        ;  // Failure

    pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
    if(pImageCodecInfo == NULL)
        ;  // Failure

    GetImageEncoders(num, size, pImageCodecInfo);

    ; j < num; ++j)
    {
         )
        {
            *pClsid = pImageCodecInfo[j].Clsid;
            free(pImageCodecInfo);
            return j;  // Success
        }
    }

    free(pImageCodecInfo);
    ;  // Failure
}

bool CaptureScreenShot(
    int nWidth,
    int nHeight,
    const std::wstring& szDestFile,
    const std::wstring& szEncoderString)
{
    UINT *pixels=new UINT[nWidth * nHeight];
    memset(pixels, , sizeof(UINT)*nWidth*nHeight);

    glFlush(); glFinish();

    glReadPixels(,,nWidth,nHeight,GL_BGRA_EXT,GL_UNSIGNED_BYTE,pixels);

    if(NULL==pixels)
        return false;

    // Initialize GDI+
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    {
        // Create the dest image
        Bitmap DestBmp(nWidth,nHeight,PixelFormat32bppARGB);

        Rect rect1(, , nWidth, nHeight);

        BitmapData bitmapData;
        memset( &bitmapData, , sizeof(bitmapData));
        DestBmp.LockBits(
            &rect1,
            ImageLockModeRead,
            PixelFormat32bppARGB,
            &bitmapData );

        int nStride1 = bitmapData.Stride;
         )
            nStride1 = -nStride1;

        UINT* DestPixels = (UINT*)bitmapData.Scan0;

        if( !DestPixels )
        {
            delete [] pixels;
            return false;
        }

        ; row < bitmapData.Height; ++row)
        {
            ; col < bitmapData.Width; ++col)
            {
                DestPixels[row * nStride1 /  + col] = pixels[row * nWidth + col];
            }
        }

        DestBmp.UnlockBits(
            &bitmapData );

        delete [] pixels;
        pixels = NULL;

        DestBmp.RotateFlip( RotateNoneFlipY );

        CLSID Clsid;
        int result = GetEncoderClsid(szEncoderString.c_str(), &Clsid);

         )
            return false;

        Status status = DestBmp.Save( szDestFile.c_str(), &Clsid );
    }
    // Shutdown GDI+
    GdiplusShutdown(gdiplusToken);

    return true;
}
void saveImage()
{
    wchar_t FullPath[MAX_PATH];
    memset( FullPath, , sizeof(FullPath) );
    std::wstring szExePath;
    if (::GetModuleFileNameW( NULL, FullPath, sizeof(wchar_t)*MAX_PATH))
    {
        szExePath = FullPath;

        int pos = szExePath.rfind( L'\\' );

         != pos )
        {
            szExePath = szExePath.substr(,pos+);
        }
    }

    std::wstring szDestFile = szExePath;
    szDestFile += L"somepic.png";

    RECT rect;
    memset(&rect,,sizeof(rect));
    HWND g_hWnd=GetFocus();
    GetClientRect(g_hWnd,&rect);

    CaptureScreenShot(
        rect.right,
        rect.bottom,
        szDestFile,
        L"image/png");
}

从这里看的http://forums.codeguru.com/showthread.php?446641-How-can-I-output-an-image-generated-with-openGL-to-an-image-file-such-as-jpg

opengl截图的更多相关文章

  1. Android OpenGL ES 开发(N): OpenGL ES 2.0 机型兼容问题整理

    在使用OpenGL ES做开发的时候,发现不是所有机型对OpenGL的代码都兼容的那么好,同样的代码在某些机型上总是会出现问题,但是在其他手机上就是好的.下面是本人总结的OpengGL 兼容问题: 一 ...

  2. iOS 截屏,openGL ES 截图,以及像素颜色判断

    代码整理了2种截图,类似.(没苹果自带那种截图彻底) 方法一: +(UIImage *)fullScreenshots{ UIWindow *screenWindow = [[UIApplicatio ...

  3. CSharpGL(27)讲讲清楚OpenGL坐标变换

    CSharpGL(27)讲讲清楚OpenGL坐标变换 在理解OpenGL的坐标变换问题的路上,有好几个难点和易错点.且OpenGL秉持着程序难以调试.难点互相纠缠的特色,更让人迷惑.本文依序整理出关于 ...

  4. OpenGL中坐标系的理解(一)

    在OpenGL中,存在着至少存在着三种矩阵,对应着函数glMatrixMode()的三个参数:GL_MODELVIEW,GL_PROJECTION,GL_TEXTURE. 以下主要描述GL_MODEL ...

  5. OpenGL 多视图与截屏

    最近看红宝书学习 OpenGL 一段时间了,写了简单的 demo 程序温习一下知识. 主要是 使用 glScissor 多视图显示画面和使用 glReadPixels 给画面截屏,使用显示列表(dis ...

  6. OpenGL阴影,Shadow Volumes(附源程序,使用 VCGlib )

    实验平台:Win7,VS2010 先上结果截图:    本文是我前一篇博客:OpenGL阴影,Shadow Mapping(附源程序)的下篇,描述两个最常用的阴影技术中的第二个,Shadow Volu ...

  7. OpenGL阴影,Shadow Mapping(附源程序)

    实验平台:Win7,VS2010 先上结果截图(文章最后下载程序,解压后直接运行BIN文件夹下的EXE程序): 本文描述图形学的两个最常用的阴影技术之一,Shadow Mapping方法(另一种是Sh ...

  8. OpenGL管线(用经典管线代说着色器内部)

    图形管线(graphics pipeline)向来以复杂为特点,这归结为图形任务的复杂性和挑战性.OpenGL作为图形硬件标准,是最通用的图形管线版本.本文用自顶向下的思路来简单总结OpenGL图形管 ...

  9. OpenGL坐标变换及其数学原理,两种摄像机交互模型(附源程序)

    实验平台:win7,VS2010 先上结果截图(文章最后下载程序,解压后直接运行BIN文件夹下的EXE程序): a.鼠标拖拽旋转物体,类似于OGRE中的“OgreBites::CameraStyle: ...

随机推荐

  1. POJ 2028

    #include <iostream> #define MAXN 200 using namespace std; int mark[MAXN]; int main() { //freop ...

  2. editplus bat语法高亮

    editplus bat语法高亮 今天需要在Windows上写批处理,因为没写过,避免关键字错误,就需要语法高亮了,editplus默认没有bat语法文件,赶紧解决. 1:到 http://www.e ...

  3. WAMP error: Forbidden You don't have permission to access /{you_app_name} on this server

    Forbidden You don't have permission to access /{you_app_name}on this server. 需要修改两处: wamp\bin\apache ...

  4. 请问view controller scene,该如何删除

    当要删除默认的view controller scene的时候,选中,按del键 注意点击中间的那个左侧按钮,打开scene列表,再选中scene,按del即可删除

  5. 编程实现linux下的shell

    /************************************************************************* > File Name: Kris_shel ...

  6. java+内存分配及变量存储位置的区别[转]

    原文来自:http://blog.csdn.net/rj042/article/details/6871030#comments Java内存分配与管理是Java的核心技术之一,之前我们曾介绍过Jav ...

  7. lintcode:最长公共子序列

    题目 最长公共子序列 给出两个字符串,找到最长公共子序列(LCS),返回LCS的长度. 样例 给出"ABCD" 和 "EDCA",这个LCS是 "A& ...

  8. java 哪些情况下会使对象锁释放

    Java_多线程_锁释放 问:Java多线程运行环境中,在哪些情况下会使对象锁释放?答:由于等待一个锁的线程只有在获得这把锁之后,才能恢复运行,所以让持有锁的线程在不再需要锁的时候及时释放锁是很重要的 ...

  9. Linux系统调用--getrlimit()与setrlimit()函数详解

    http://www.cnblogs.com/niocai/archive/2012/04/01/2428128.html 功能描述:获取或设定资源使用限制.每种资源都有相关的软硬限制,软限制是内核强 ...

  10. 根据ip查询地区,经纬度等-geoip2

    这项工作难度主要在数据上,数据越准确越有利. 1. 下载数据文件: http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.m ...