graphics.copyfromscreen

Where is the "copytoscreen()" counterpart of "copyfromscreen()"
I want to highlight a rectangle on the screen by pixel manipulation.
It looks like copyfromscreen() gets me the original pixels but how do I put the altered pixels back on the screen

thanks



Answer this question

graphics.copyfromscreen

  • dj_develop

    You can save the Rectangle to Memory Bitmap and then use SetPixel() method of Bitmap setting each pixel in its location then draw the whole image at its original location!

    I hope this will Help!

    Best Regards,



  • WishfulDoctor

    I was hoping to avoid using the windows api.
    I know how to do what I want using bitblt() and other api functions.
    Yours is smaller though so I will give it a try.

    thanks.



  • Tryin2Bgood

    You'll need some P/Invoke to create a Graphics object to render to the display. Here's some sample code, it makes a copy of the upper-left corner of the screen and puts it back with a 10-pixel offset:

    [System.Runtime.InteropServices.DllImport("gdi32.dll")]
    private static extern IntPtr CreateDC(string driver, string device, IntPtr res1, IntPtr res2);
    [System.Runtime.InteropServices.DllImport("gdi32.dll")]
    private static extern bool DeleteDC(IntPtr hDc);

    private void button1_Click(object sender, EventArgs e) {
    Bitmap bmp = new Bitmap(100, 100);
    Graphics grb = Graphics.FromImage(bmp);
    grb.CopyFromScreen(0, 0, 0, 0, bmp.Size);
    IntPtr hdc = CreateDC("DISPLAY", "DISPLAY", IntPtr.Zero, IntPtr.Zero);
    Graphics grs = Graphics.FromHdc(hdc);
    grs.DrawImage(bmp, 10, 10);
    grs.Dispose();
    grb.Dispose();
    DeleteDC(hdc);
    }



  • graphics.copyfromscreen