小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

用C#提取鼠標所指的像素

 ShangShujie 2008-05-17

原創(chuàng) 用 C# 提取鼠標所指的像素

此出是調(diào)研WinAPI,具體代碼如下

1、調(diào)用API的類
程序代碼 程序代碼


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

namespace Desktop
{
    public class Win32APICall
    {
        [DllImport("gdi32.dll",EntryPoint="DeleteDC")]
        public static extern IntPtr DeleteDC(IntPtr hdc);

        [DllImport("gdi32.dll",EntryPoint="DeleteObject")]
        public static extern IntPtr DeleteObject(IntPtr hObject);

        [DllImport("gdi32.dll",EntryPoint="BitBlt")]
        public static extern bool BitBlt(IntPtr hdcDest,int nXDest,
            int nYDest,int nWidth,int nHeight,IntPtr hdcSrc,
            int nXSrc,int nYSrc,int dwRop);

        [DllImport ("gdi32.dll",EntryPoint="CreateCompatibleBitmap")]
        public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, 
            int nWidth, int nHeight);

        [DllImport ("gdi32.dll",EntryPoint="CreateCompatibleDC")]
        public static extern IntPtr CreateCompatibleDC(IntPtr hdc);

        [DllImport ("gdi32.dll",EntryPoint="SelectObject")]
        public static extern IntPtr SelectObject(IntPtr hdc,IntPtr hgdiobjBmp);

        [DllImport("user32.dll", EntryPoint="GetDesktopWindow")]
        public static extern IntPtr GetDesktopWindow();

        [DllImport("user32.dll",EntryPoint="GetDC")]
        public static extern IntPtr GetDC(IntPtr hWnd);

        [DllImport("user32.dll",EntryPoint="GetSystemMetrics")]
        public static extern int GetSystemMetrics(int nIndex);

        [DllImport("user32.dll",EntryPoint="ReleaseDC")]
        public static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDC);

        public static Bitmap GetDesktop()
        {
            int screenX;
            int screenY;
            IntPtr hBmp;
            IntPtr  hdcScreen = GetDC(GetDesktopWindow());
            IntPtr hdcCompatible = CreateCompatibleDC(hdcScreen);

            screenX = GetSystemMetrics(0);
            screenY = GetSystemMetrics(1);
            hBmp = CreateCompatibleBitmap(hdcScreen, screenX, screenY);

            if (hBmp!=IntPtr.Zero)
            {
                IntPtr hOldBmp = (IntPtr) SelectObject(hdcCompatible, hBmp);
                BitBlt(hdcCompatible, 0, 0,screenX,screenY, hdcScreen, 0, 0,13369376);
            
                SelectObject(hdcCompatible, hOldBmp);
                DeleteDC(hdcCompatible);
                ReleaseDC(GetDesktopWindow(), hdcScreen);
            
                Bitmap bmp = System.Drawing.Image.FromHbitmap(hBmp); 
            
                DeleteObject(hBmp);
                GC.Collect();
            
                return bmp;
            }
        
            return null;
        }
    }
}
 



2、聲明
在需要的應(yīng)用程序聲明
private Bitmap myBitmap;

3、抓取

myBitmap = Win32APICall.GetDesktop();

4、結(jié)束

Color myColor = myBitmap.GetPixel(MousePosition.X,MousePosition.Y);
            label1.BackColor = myColor;

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多