sdauxxrs_cx 2017-11-19 02:54 采纳率: 0%
浏览 847

c#实现巴恩斯利蕨,运行出问题,求助解决

代码如下,一个菜单栏一个picturebox控件,一运行就卡死,显示是Bitmap myBitmap = new Bitmap(pictureBox1.Width, pictureBox1出了问题,但是不完全知道怎么改啊哭
private void showToolStripMenuItem_Click(object sender, EventArgs e)
{
int r;
double x, y;
x = 0.0; y = 0.0;

        Random ra = new Random(0);//种子

        for (int i = 0; i < 50000; i++)
        {
            Random ran = new Random();
            r = ran.Next()%100;//随机数

            if (r< 0)
            {
                x = 0;
                y = 0.16 * y;
            }
            else if (r<8)
            {
                x = 0.2 * x - 0.26 * y;
                y = 0.23 * x + 0.22 * y + 1.6;
            }
            else if (r<15)
            {
                x = -0.15 * x + 0.28 * y;
                y = 0.26 * x + 0.24 * y + 0.44;
            }
            else
            {
                x = 0.85 * x + 0.04 * y;
                y = -0.04 * x + 0.85 * y + 1.6;
            }
            Bitmap myBitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            myBitmap.SetPixel((int)((x / 10)), (int)((y / 10 - 0.3)), Color.Green);

            pictureBox1.Image = myBitmap;
        }

    }
  • 写回答

3条回答 默认 最新

  • shifenglv 2017-11-19 04:50
    关注

    每次循环都要重新分配空间,当然很卡。把“Bitmap myBitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);”放到循环之外就好了。

    评论

报告相同问题?