Bitmap.GetPixel让我在C#中给出错误信息

时间:2016-10-25 20:50:58

标签: c#

    List<Bitmap> bitrecord = new List<Bitmap>();
    List<String> filerecord = new List<String>();
    string tempfilewrite = "";

    private void timer1_Tick(object sender, EventArgs e)
    {
        this.Hide();
    }

    private void timer2_Tick(object sender, EventArgs e)
    {
        using (Bitmap bitrecorder = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
        {
            using (Graphics recordgraphics = Graphics.FromImage(bitrecorder))
            {
                recordgraphics.CopyFromScreen(new Point(0, 0), Point.Empty, Screen.PrimaryScreen.Bounds.Size);
            }
            bitrecord.Add(bitrecorder);
        }
    }

    private void timer3_Tick(object sender, EventArgs e)
    {
        for (int z = 1; z < bitrecord.ToArray().Length; z++)
        {
            Bitmap bit = bitrecord[z];
            tempfilewrite = "" + z;
            for (int x = 1; x < Screen.PrimaryScreen.Bounds.Width; x++)
            {
                for (int y = 1; y < Screen.PrimaryScreen.Bounds.Height; y++)
                {
                    tempfilewrite += ", (" + x + ", " + y + ", " + bit.GetPixel(x, y).R + ", " + bit.GetPixel(x, y).G + ", " + bit.GetPixel(x, y).B + ")";
                }
            }
            filerecord.Add(tempfilewrite);
        }
        System.IO.File.WriteAllLines(@"C:\Public\WriteLines.txt", filerecord);
        timer3.Stop();
    }
}

以上是程序的代码,该程序应该拍摄桌面的几张照片并将其保存在文本文件中。但是,当我启动程序时,它给出了一个错误,我在使用bit.GetPixel(x,y)获取像素的行上有System.ArgumentException。如果有人知道如何解决这个问题,那就太棒了,谢谢。

0 个答案:

没有答案
相关问题