简体   繁体   中英

Graphics graphics = Graphics.FromImage(BitMap_1); // <--This is not allowed? How

Graphics graphics = Graphics.FromImage(BitMap_1); // <--This is not allowed? How can I fix it?How can I declare graphics as global? Here is some more code... Here is some more code... Here is some more code... Here is some more code...

public partial class Form1 : Form
{
    string WAV_filePath  = @"";
    string MIDI_filePath = @"";
    string filePath = @"C:\Users\Steffan\Desktop\guitar\Gert toets die Elektroniese Konsertina.wav";//Guitar 2.wav";//Sine Wave 440Hz.wav";
    SoundPlayer player1 = new SoundPlayer();
    byte[] RawWaveDataArray = new byte[100];
    Int16[] Data_16Bit = new Int16[100];
    int NumberOfSamples = 0;
    bool PLAY_ = false;
    Point[] Points = new Point[886];
    // Create pen.
    Pen Pen_ = new Pen(Color.White, 0);
    Bitmap BitMap_1 = new Bitmap(1138, 72);
    Graphics graphics = Graphics.FromImage(BitMap_1); // <--This is not allowed? How can I fix it?How can I declare graphics as global?

    public Form1()
    {
        InitializeComponent();
    }
    private void timer1_Tick(object sender, EventArgs e)
    {
        if (PLAY_ == true)
        {
            Wave_x_Inc = 0;
            graphics.Clear(Color.Black);
            for (int x = 0; x < 886; x++)
            {
                Points[x]  = new Point(Wave_x_Inc, (int)((Data_16Bit[DataIndex] * 0.002F) + (pictureBox4.Height / 2)));
                Wave_x_Inc = Wave_x_Inc + 2;

                DataIndex = DataIndex + 2;
                if (DataIndex > Data_16Bit.Length/2) { DataIndex = 0; x = 886; }
            }

            if (Wave_x_Inc > pictureBox4.Width) { Wave_x_Inc = 0; }

            graphics.DrawBeziers(Pen_, Points);

            WaveLengthCounter = WaveLengthCounter + 886;

            int Temp_Val = WaveLengthCounter / DataLenth_Fraction;

            if (Temp_Val <= 300) { trackBar1.Value = Temp_Val; }
            else { trackBar1.Value = 0; }

            if (WaveLengthCounter > Data_16Bit.Length/2)
            {
                WaveLengthCounter = 0;
            }
            pictureBox4.Image = BitMap_1;
        }
    }

}

Try this, it may help you.

var bitmap = new Bitmap(width, height);
var graphics = Graphics.FromImage(bitmap);

graphics.DrawRectangle(Pens.Black, 0, 0, 10, 10);

bitmap.Save("MyShapes.png");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM