0

これを使用して:

 public static void DrawNormalizedAudio(ref float[] data, PictureBox pb,
    Color color)
{
    Bitmap bmp;
    if (pb.Image == null)
    {
        bmp = new Bitmap(pb.Width, pb.Height);
    }
    else
    {
        bmp = (Bitmap)pb.Image;
    }

    int BORDER_WIDTH = 5;
    int width = bmp.Width - (2 * BORDER_WIDTH);
    int height = bmp.Height - (2 * BORDER_WIDTH);

    using (Graphics g = Graphics.FromImage(bmp))
    {
        g.Clear(Color.Black);
        Pen pen = new Pen(color);
        int size = data.Length;
        for (int iPixel = 0; iPixel < width; iPixel++)
        {
            // determine start and end points within WAV
            int start = (int)((float)iPixel * ((float)size / (float)width));
            int end = (int)((float)(iPixel + 1) * ((float)size / (float)width));
            float min = float.MaxValue;
            float max = float.MinValue;
            for (int i = start; i < end; i++)
            {
                float val = data[i];
                min = val < min ? val : min;
                max = val > max ? val : max;
            }
            int yMax = BORDER_WIDTH + height - (int)((max + 1) * .5 * height);
            int yMin = BORDER_WIDTH + height - (int)((min + 1) * .5 * height);
            g.DrawLine(pen, iPixel + BORDER_WIDTH, yMax, 
                iPixel + BORDER_WIDTH, yMin);
        }
    }
    pb.Image = bmp;
}

この行でエラーが発生しました:

g.DrawLine(pen, iPixel + BORDER_WIDTH, yMax, 
            iPixel + BORDER_WIDTH, yMin);

それは操作オーバーフロー(ゼロで割り切れない)またはそのようなことを言います。問題の手がかりはありますか?ありがとう。

更新:関数を呼び出すために使用するコードは次のとおりです。

fileName = "c:\\sound\\happy_birthday.wav";

        byte[] bytes = File.ReadAllBytes(fileName);
        float[] getval = FloatArrayFromByteArray(bytes);
        DrawNormalizedAudio(ref getval, pictureBox1, Color.White);
4

3 に答える 3

0

minmaxは間違っていた、

float min = float.MinValue;
float max = float.MaxValue;
于 2012-10-27T22:55:31.400 に答える
0

あなたはゼロで割っています。この操作は無効です。渡す値がDrawLine0 でないことを確認してください。

于 2011-03-17T09:01:31.903 に答える