本帖最后由 JIMODEDUZOU 于 2010-10-24 21:49:57 编辑

解决方案 »

  1.   

    Getpixel、Setpixel很低效 
    循环又慢 
    可用Bitmap.LockBits获取BitmapData数据后处理
      

  2.   

    思路1:
    矩阵变换
    全部的点都先画成(0,0,0),利用变换矩阵就可以了(GDI+编程)
    思路2:
    在protected override void OnPaint(PaintEventArgs e)事件里采取双缓存
      

  3.   

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            Bitmap bmp = new Bitmap(2, 2);
                bmp.SetPixel(0, 0, Color.Black);
                bmp.SetPixel(1, 1, Color.Black);
                bmp.SetPixel(1, 0, Color.White);
                bmp.SetPixel(0, 1, Color.White);            this.BackgroundImage = bmp;
            }
        }
      

  4.   

    上面代码的思路就是构造一个2*2的bmp,对角像素分别为黑和白,然后放到BackgroundImage中,因为Winform会自动将图平铺,这样就是你要的效果了
      

  5.   

    可以设定第一张BMP平铺的左上角坐标吗?
      

  6.   

    这个就不好控制了,不过你可以用其它的替代方法,比如在Form中放一个Panel,Panel的位置可以被设置,然后把图片设置为panel的BackgroundImage
      

  7.   


    this.BackColor = Color.FromArgb(0, 0, 0);
     Bitmap bmp = new Bitmap(ScreenWidth, ScreenHeight);            // Lock the bitmap's bits.  
                Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
                System.Drawing.Imaging.BitmapData bmpData =
                    bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
                    bmp.PixelFormat);            // Get the address of the first line.
                IntPtr ptr = bmpData.Scan0;            // Declare an array to hold the bytes of the bitmap.
                // This code is specific to a bitmap with 24 bits per pixels.
                int bytes = bmp.Width * bmp.Height * 3;
                byte[] rgbValues = new byte[bytes];            // Copy the RGB values into the array.
                System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);            // 间隔一个子像素为255
                //第一个:(255,0,255) 第二个:(0,255,0) 如此交替重复.
                for (int counter = 0; counter < rgbValues.Length; counter += 2)
                    rgbValues[counter] = 255;            // Copy the RGB values back to the bitmap
                System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);            // Unlock the bits.
                bmp.UnlockBits(bmpData);            // Draw the modified image.
                e.Graphics.DrawImage(bmp, 0,0);
    //为什么画出来还是全黑一片啊?......