C# GetPixel and SetPixel

using
 System.Drawing;
using
 System.Runtime.InteropServices;
using
 System.Windows.Forms;

[DllImport
( "user32.dll"
 )]
static
 extern
 IntPtr
 GetDC( IntPtr
 hWnd );
[DllImport
( "user32.dll"
 )]
static
 extern
 int
 ReleaseDC( IntPtr
 hWnd, IntPtr
 hDC );
[DllImport
( "gdi32.dll"
 )]
static
 extern
 int
 GetPixel( IntPtr
 hDC, int
 x, int
 y );
[DllImport
( "gdi32.dll"
 )]
static
 extern
 int
 SetPixel( IntPtr
 hDC, int
 x, int
 y, int
 color );

static
 public
 Color
 GetPixel( Control
 control, int
 x, int
 y )
{
    Color
 color = Color
.Empty;
    if
 (control != null
)
    {
        IntPtr
 hDC = GetDC( control.Handle );
        int
 colorRef = GetPixel( hDC, x, y );
        color = Color
.FromArgb(
            (int
)(colorRef & 0x000000FF),
            (int
)(colorRef & 0x0000FF00) >> 8,
            (int
)(colorRef & 0x00FF0000) >> 16 );
        ReleaseDC( control.Handle, hDC );
    }
    return
 color;
}
static

你可能感兴趣的:(C#,c#,null,user)