需要提高OpenGL的屏幕截图的分辨率 [英] Need to improve resolution of screenshot from OpenGL

查看:462
本文介绍了需要提高OpenGL的屏幕截图的分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从OpenTK的当前场景中获得具有高分辨率的屏幕快照.我正在使用GL.ReadPixels来获取场景照片.我发现它的分辨率/质量较低.

I want to get a screen shot from current scene in OpenTK with good resolution. I am using GL.ReadPixels to get a photo for the scene.If I save the photo to disk; I found it with low resolution/quality.

以下C#代码用于获取现场照片:

following C# code is used to get a photo for the scene :

位图bmp = null;

Bitmap bmp = null;

    if (GraphicsContext.CurrentContext != null)
    {
        glControl_window.Invalidate();
        int w = glControl_window.ClientSize.Width;
        int h = glControl_window.ClientSize.Height;
        bmp = new Bitmap(w, h);
        System.Drawing.Imaging.BitmapData data =
        bmp.LockBits(glControl_window.ClientRectangle, 
        System.Drawing.Imaging.ImageLockMode.ReadWrite, 
        System.Drawing.Imaging.PixelFormat.Format24bppRgb);


        GL.ReadPixels(0, 0, w, h, OpenTK.Graphics.OpenGL.PixelFormat.Bgr, 
        PixelType.UnsignedByte, data.Scan0);
        bmp.UnlockBits(data);

        bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

    }

初始化OpenTK时使用:

when Initialize OpenTK use :

         this.glControl_window = new OpenTK.GLControl(new 
         OpenTK.Graphics.GraphicsMode(new OpenTK.Graphics.ColorFormat(32), 
         24,8,4,new OpenTK.Graphics.ColorFormat(0),2,false));

我使用OpenTK的大小调整事件:

with resize event of OpenTK I use :

            GL.Viewport(0, 0, Width, Height);

我使用的带有OpenTK绘画事件(通过鼠标启用放大/缩小):

with paint event of OpenTK I use (to enable zoom in/out by mouse) :

              float aspectRatio;
            if (Height == 0 || Width == 0) aspectRatio = 1f; else 
               aspectRatio = Width / (float)Height;

            double W = 20 * aspectRatio / CameraZoomScale, H = 20 / 
               CameraZoomScale;
            GL.Ortho(-0.5 * W, 0.5 * W, -0.5 * H, 0.5 * H, -600.0f, 600.0f);

我需要:

1.提高GL.ReadPixels期间令牌屏幕截图的分辨率.

1.increase the resolution of the token screen shot during GL.ReadPixels.

推荐答案

我假设您知道您要在这里要求两个非常不同的事情.

I assume you know that you are asking for two very different things here.

使用GL.readpixels()从帧缓冲区读取的像素数始终是与缓冲区大小相对应的像素数.即1280x720或类似的尺寸.

The number of pixels to be read from a frame buffer using GL.readpixels() is always going to be the number of pixels corresponding to the buffer size. i.e. 1280x720 or something like that.

能够读取更多像素的唯一方法是增大OpenGL帧缓冲区的大小/分辨率.

The only way to be able to read more pixels would be to increase the size/resolution of the OpenGL frame buffer.

查找您的OpenTK代码中用于初始化打开的gl窗口并提高窗口分辨率的部分.寻找类似的东西:

Look for the part of your OpenTK code that initializes the open gl window and increase the resolution of the window. Look for something like:

public MainWindow()
    : base(
           1280, // initial width
           720,  // initial height
           ...
    )
{
    // your code
}

,然后根据需要更改分辨率.您可能还必须按照以下说明覆盖GameWindow类中的OnResize方法:

and change the resolution as desired. You might also have to override the OnResize method in your GameWindow class as described here: How to change the viewport resolution in OpenTK

将位图保存到磁盘后,任何提高"分辨率的尝试都将涉及升级现有图像.这最终将导致大量像素,但还会根据图像和所使用的放大算法而引入放大伪像.您可以在Wikipedia上阅读有关不同图像缩放算法的更多信息:图像缩放算法

Once the bitmap has been saved to disk, any attempts to "increase" the resolution will involve upscaling the already existing image. This will ultimately result in a larger number of pixels, but also introduce upscaling artifacts depending on the image and which upscaling algoritm that is used. You can read more on different image scaling algoritms on wikipedia: Image scaling Algorithms

这篇关于需要提高OpenGL的屏幕截图的分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆