1:如何获取某个控件指定位置的像素信息?如panel的(1,1)像素的颜色?2:为了体现算法,使用设置像素点颜色的方法画直线和填充,GDI+里似乎没有像素着色的方法,用FillRectangle画长宽为1的矩形代替,性能差的多吗?当然性能要求不高。3:如果GDI+里没有像素着色的函数,怎么调用GDI的函数?4:鼠标事件。像画笔一样拖拽画线,涉及三个事件的响应down,move,up,一个画线动作分三个事件完成似乎不爽,有没有直接这个动作的事件,或者对这三个事件重新封装。怎么做?谢谢哪位指点一下!

解决方案 »

  1.   

    1.用GDI API函数GetPixel
    2.
    3.用GDI API函数SetPixel
    4.在windows中都是这三个事件,无论是C#,vc等 [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);
    [DllImport("User32.dll")]
    static extern IntPtr GetWindowDC(IntPtr hWnd);
    [DllImport("User32.dll")]
    static extern int ReleaseDC(IntPtr hWnd,IntPtr hDC);
      

  2.   

    关于API的引用,请参考例:
    public class IniReader
    {
    public IniReader()
    {
    } private string ReadIni(string iniFile, string iniSection, string iniKey, string iniDefault)
    {
    string iniRet = new string(' ', 0xff);
    GetPrivateProfileString(ref iniSection, ref iniKey, ref iniDefault, ref iniRet, 254, ref iniFile);
    return iniRet.Substring(0,iniRet.IndexOf("\0"));
    }
    [DllImport("kernel32", EntryPoint="GetPrivateProfileStringA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
    private static extern int GetPrivateProfileString([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpApplicationName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpKeyName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpDefault, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpReturnedString, int nSize, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpFileName);}
      

  3.   

    GetPixel和SetPixel里的color都是32位的长整型,怎么转换到Color类,是不是Color.FromArgb(int); 直接作参数?
      

  4.   

    不可以
    int r,g,b;
    r = (byte)color;
    g = (int)(color&0x0000ff00)>>8;
    b = (int)(color&0x00ff0000)>>16;GetPixel得到的color是0x00BBGGRR
    Color.FromArgb(int)中的是0xAARRGGBB所以要转换
      

  5.   

    谢谢。
    还有个问题,我想画线填充像素点时保存原来像素点,画好时,原来像素点信息就保存在一个Queue里。这样,拖拽移动刷新时只要队列中像素重绘,但是这个Queue放在什么地方?呵呵,是设计问题。画线函数是一个类的static方法,缓冲区(Queue)放在Form类里了。画线时不能直接用。现在我用out参数传过去,再加入像素点信息,好像不太好,能不能指点一下?