Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

C#
  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;
        }
    }
 
Share this answer
 
v2
Comments
savan.v 25-Jun-15 3:10am    
I want to capture screen shot of Desktop by using opengl DLL in C#

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900