我想将程序的结果从十六进制更改为十进制 任何人都可以帮助我吗?

I want to change the result of my program from Hexadeimal to Decimal Can Any One help me?

我已经阅读了 bmp 文件并获得了十六进制结果,现在我想更改 结果只保留为十进制 谁能帮帮我???

我使用了这些代码,所以我得到了十六进制结果:

private void ChosseBtn_Click(object sender, EventArgs e)
{
    using (OpenFileDialog dlg = new OpenFileDialog())
    {
        dlg.Title = "Open Image";
        dlg.Filter = "bmp files (*.bmp)|*.bmp";

        if (dlg.ShowDialog() == DialogResult.OK)
        {
            var colorCodes = this.GetColorCodes(dlg.FileName);
            var str = string.Join(Environment.NewLine,
            colorCodes.Select<int[], string>(line => string.Join(" ", line.Select<int, string>(code => string.Format("{0:X8}", code))))); // string.Format("{0:X6}", code & 0x00FFFFFF) if you want RRGGBB format
            textBox1.Text = str; // requires textBox1.Multiline = true, better have monospaced font
        }
    }
}
private int[][] GetColorCodes(string path)
{
    var bitmap = new Bitmap(path);
    return Enumerable.Range(0, bitmap.Height)
                     .Select<int, int[]>(y => Enumerable.Range(0, bitmap.Width)
                     .Select<int, int>(x => bitmap.GetPixel(x, y).ToArgb()).ToArray()).ToArray();
}

我在文本框中得到了一个结果,如 FF00 但我需要像这样的小数 0 对于白色或 255 对于黑色..

您可能从某处复制了此代码,但不知道如何根据您的需要进行调整。

您需要更改的行是这一行:

colorCodes.Select<int[], string>(line => string.Join(" ", line.Select<int, string>(code => string.Format("{0:X8}", code)))));

string.Format("{0:X8}", code) 将整数格式化为十六进制。如果您不想要十六进制,只需执行 ToString:

colorCodes.Select<int[], string>(line => string.Join(" ", line.Select(x => x.ToString()))));