好像只能靠api吧,跟指针有什么关系?

解决方案 »

  1.   

    Copied from MSDN Lib For .NetBitmap.SetPixel:设置 Bitmap 对象中指定像素的颜色。[C#]
    [Serializable]
    [ComVisible(true)]
    public void SetPixel(
       int x,
       int y,
       Color color
    );
    参数

    要设置的像素的 x 坐标。 

    要设置的像素的 y 坐标。 
    color 
    Color 结构,它表示要分配给指定像素的颜色。 
    返回值
    此方法不返回值。示例
    [Visual Basic, C#] 下面的示例旨在用于 Windows 窗体,它需要 PaintEventArgs e(这是 Paint 事件处理程序的参数)。代码执行下列操作: 创建一个 Bitmap 对象。 
    将位图中每个像素的颜色设置为黑色。 
    绘制该位图。 
    [Visual Basic] 
    Public Sub SetPixel_Example(e As PaintEventArgs)' Create a Bitmap object from a file.Dim myBitmap As New Bitmap("Grapes.jpg")' Draw myBitmap to the screen.e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _myBitmap.Height)' Set each pixel in myBitmap to black.Dim Xcount As IntegerFor Xcount = 0 To myBitmap.Width - 1Dim Ycount As IntegerFor Ycount = 0 To myBitmap.Height - 1myBitmap.SetPixel(Xcount, Ycount, Color.Black)Next YcountNext Xcount' Draw myBitmap to the screen again.e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, _myBitmap.Height)End Sub
    [C#] 
    public void SetPixel_Example(PaintEventArgs e){// Create a Bitmap object from a file.Bitmap myBitmap = new Bitmap("Grapes.jpg");// Draw myBitmap to the screen.e.Graphics.DrawImage(myBitmap,0,0,myBitmap.Width,myBitmap.Height);// Set each pixel in myBitmap to black.for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++){for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++){myBitmap.SetPixel(Xcount, Ycount, Color.Black);}}// Draw myBitmap to the screen again.e.Graphics.DrawImage(myBitmap,myBitmap.Width,0,myBitmap.Width,myBitmap.Height);}
      

  2.   

    我想进行图象处理,比如位操作等,用setpixel很慢的
      

  3.   

    你可以在unsafe代码中用指针。------------------------------
    我是一只小小鸟
    欢迎交流!尽管问我吧,我会帮你解决的!
    尽快结帖哦!我是CSDN的菜鸟,我想获得一颗星!支持我吧!
    MSN&Mail: [email protected]
      

  4.   

    .Net的应用程序效率都很慢,尤其是GDI+的效率更是蜗牛级的:(如果应用程序对速度的要求很高,还是推荐使用VC++的本地代码。我前不久的一个项目也需要大量的图形图象处理,这部分功能我使用的是VC++来实现的,行成一个ATL控件,嵌入.Net的程序中。即使使用Win32 API对HBITMAP进行操作效果也不好,因为.Net的托管代码机制,在非托管代码和托管代码进行通讯的时候,大量的类型安全检查和转换使效率很低,而且频繁的、大数量的交换会导致不可预期的错误——微软自己都这样说,真是:(
      

  5.   

    这样看来C#不是适合做图象处理,我觉得Java的swing库和awt库倒是蛮好的。