使用 C# 不会更改二进制文件的十六进制值

Binary file's hex value won't change using C#

我的 C# 代码无法更改第 13 个位置的十六进制值。

这是 C# 我的代码:

private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog openFileDialog = new OpenFileDialog();
    if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
        string fileName = openFileDialog.FileName;
        textBox1.Text = fileName;
    }
}

private void button2_Click(object sender, EventArgs e)
{
    string fileName = textBox1.Text;
    using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
    {
        stream.Position = 13;
        stream.WriteByte(0x00);
    }
}

你有 stream.Position = 13;(13 是十进制) 您的图片指向 13 进制(十进制为 19),因此您需要 stream.Position = 0x13