【问题标题】:I want to change the result of my program from Hexadeimal to Decimal Can Any One help me?我想将程序的结果从十六进制更改为十进制有人可以帮助我吗?
【发布时间】:2019-04-19 08:44:38
【问题描述】:

我已经阅读了 bmp 文件并得到了 HexDecimal 结果,现在我想更改 结果只有小数 任何人都可以帮助我吗???

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

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 黑色..

【问题讨论】:

  • 调查你为什么使用string.Format("{0:X8}", code),例如看看here
  • 我了解 Mr.@HansKesting 谢谢您的帮助

标签: c# decimal bmp


【解决方案1】:

您可能从某个地方复制了此代码,但不知道如何根据需要对其进行调整。

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

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()))));

【讨论】:

  • 亲爱的@sweeper 是的,我在这个网站上用这个link 提出了另一个问题,我真的很需要它,所以现在我的老板让我将十六进制更改为十进制。所以我开始问你我的朋友,当然非常感谢!!!
  • 非常感谢您的帮助,但line.Select(int.ToString) 部分存在错误,错误文本为 **Error 1 The type arguments for method 'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)' 无法从用法中推断出来。尝试明确指定类型参数。 C:\Users\Home\Desktop\New 文件夹\Sample1_0\Experiment0_1\Form1.cs 41 78 Experiment0_1 ** 我该怎么办?顺便说一句,我是这种语言的新手......
猜你喜欢
  • 1970-01-01
  • 2019-03-22
  • 2010-09-13
  • 1970-01-01
  • 2017-10-13
  • 1970-01-01
  • 1970-01-01
  • 2017-07-19
  • 1970-01-01
相关资源
最近更新 更多