如何在c#中使用opengl捕获桌面的截图? [英] How to capture the screenshot of desktop using opengl in c#?
问题描述
我想拍一张桌面屏幕截图,这里是下面给出的代码,有人可以帮帮我吗?
公共位图GrabScreenshot()
{
位图bmp =新位图(this.ClientSize.Width,this.ClientSize.Height);
System.Drawing.Imaging.BitmapData data = bmp.LockBits(this.ClientRectangle,System.Drawing.Imaging.ImageLockMode.WriteOnly,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
CsGL.OpenGL.GL .glReadPixels(0,0,600,600,CsGL.OpenGL.GL.GL_3D,CsGL.OpenGL.GL.GL_8X_BIT_ATI,data.Scan0);
CsGL.OpenGL.GL.glFinish();
bmp.UnlockBits(data);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
返回bmp;
}
private void button1_Click(object sender,EventArgs e)
{
GrabScreenshot();
位图bmp = GrabScreenshot();
bmp.Save(C:\\ temp \\ test.jpg,System.Drawing.Imaging.ImageFormat.Jpeg);
}
这是我用来进行屏幕排序桌面的代码但我得到黑屏任何人都可以帮我
I want to take a screen shot of Desktop screen, here is the code given below, can anybody help me?
public Bitmap GrabScreenshot()
{
Bitmap bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
System.Drawing.Imaging.BitmapData data = bmp.LockBits(this.ClientRectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
CsGL.OpenGL.GL.glReadPixels(0, 0, 800, 600, CsGL.OpenGL.GL.GL_3D, CsGL.OpenGL.GL.GL_8X_BIT_ATI, data.Scan0);
CsGL.OpenGL.GL.glFinish();
bmp.UnlockBits(data);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
return bmp;
}
private void button1_Click(object sender, EventArgs e)
{
GrabScreenshot();
Bitmap bmp = GrabScreenshot();
bmp.Save("C:\\temp\\test.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
}
this is the code i am using to take screen sort of desktop but i am getting black screen any one can help me
推荐答案
private void button1_Click(object sender, EventArgs e)
{
Image newone = CaptureScreen();
//This variable s i m using to create different names of my snaps on basis of time
string s = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss:ffff").Replace('.', 'a').Replace(':', 'b');
// MessageBox.Show(s);
newone.Save(@"C:\Users\pandasa\Desktop\Snaps\"+s+".jpg");
}
private Image CaptureScreen()
{
Rectangle screenSize = Screen.PrimaryScreen.Bounds;
Bitmap target = new Bitmap(screenSize.Width, screenSize.Height);
using (Graphics g = Graphics.FromImage(target))
{
g.CopyFromScreen(0, 0, 0, 0, new Size(screenSize.Width, screenSize.Height));
}
return target;
}
}
这篇关于如何在c#中使用opengl捕获桌面的截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!