最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to take a screen shot with OpenTK - Stack Overflow

programmeradmin1浏览0评论

I came here from how to capture the image drawn using opentk. First, I don't have access to the object "glControl1" in the example. My main window inherits from OpenTK.Windowing.Desktop.GameWindow. Next, the image I'm getting seems to be really blurry and has repeated images horizontally. Finally, I can't access all the members and fields that the example used so I extracted them differently and I'm not sure if they are the same or not.

Here is my version of "TakeScreenshot()" but I do not have their solution of "GLrefresh()"

public Bitmap TakeScreenshot()
{
    if (this.Context == null)
        throw new Exception("the \"Context\" was null ");
    int w = Size.X;
    int h = Size.Y;
    
    Box2i boxFromGameWindow = this.ClientRectangle;
    
    
    Vector2i bottomCoordinate = boxFromGameWindow.Min;
    Vector2i topCoordinate = boxFromGameWindow.Max;
    Vector2i sizeOfWindowVector = boxFromGameWindow.Size;
    Point topLeftPoint = new Point(bottomCoordinate[0], topCoordinate[1]);
    Size sizeOfWindow = new Size(sizeOfWindowVector[0], sizeOfWindowVector[1]);

    Rectangle convertedRectangle = new Rectangle(0, 0, sizeOfWindowVector[0], sizeOfWindowVector[1]);

    Bitmap bmp = new Bitmap(sizeOfWindowVector[0], sizeOfWindowVector[1]);
    System.Drawing.Imaging.BitmapData data =
        bmp.LockBits(convertedRectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly, bmp.PixelFormat);


    GL.ReadPixels(0, 0,   sizeOfWindowVector[0], sizeOfWindowVector[1], PixelFormat.Rgb, PixelType.UnsignedByte, data.Scan0);
    bmp.UnlockBits(data);

    bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

    
    return bmp;
}
发布评论

评论列表(0)

  1. 暂无评论