Graphics Graphics=图形.FromImage(BitMap_1);//<--这是不允许的?怎样

本文关键字:Graphics lt-- 不允许 怎样 FromImage 图形 BitMap | 更新日期: 2023-09-27 18:00:34

Graphics Graphics=Graphics。FromImage(BitMap_1);//&lt--这是不允许的?我该怎么修?如何将图形声明为全局图形?这里还有一些代码。。。这里还有一些代码。。。这里还有一些代码。。。这里还有一些代码。。。

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;
        }
    }

}

Graphics Graphics=图形.FromImage(BitMap_1);//<--这是不允许的?怎样

试试这个,它可能会对你有所帮助。

var bitmap = new Bitmap(width, height);
var graphics = Graphics.FromImage(bitmap);
graphics.DrawRectangle(Pens.Black, 0, 0, 10, 10);
bitmap.Save("MyShapes.png");