【问题标题】:Need to calculate the Value of a pixel [closed]需要计算一个像素的值[关闭]
【发布时间】:2011-11-15 03:35:32
【问题描述】:

我有一个 RGBA 值, R - 255, G - 103, B - 103, 阿尔法 - 103。

需要(RGB)颜色值的组合。示例 - 26532.(颜色值/像素值的组合)

描述 - 图像由像素组成,每个像素都有颜色组合(如 - RGB)。 需要计算图像的均值,我们需要像素的唯一值。 每个像素有4个颜色值但需要像素值(颜色值的组合)

【问题讨论】:

标签: c#


【解决方案1】:

您可以使用 BitConverter 将 RGBA 字节转换为单个 int 值:

        byte[] components = new byte[4];
        components[0] = 103;        // blue
        components[1] = 103;        // green
        components[2] = 255;        // red
        components[3] = 103;        // alpha

        int pixelValue = BitConverter.ToInt32(components, 0);

【讨论】:

    【解决方案2】:

    如果您知道像素颜色值,您应该能够对每个像素进行循环,并即时计算像素值。

    相关问题:

    How can I iterate through each pixel in a .gif image in C#?

    How to calculate the average rgb color values of a bitmap

    【讨论】:

      【解决方案3】:
      int value = Color.FromArgb(103, 103, 255, 103).ToArgb()
      

      【讨论】:

      • 我使用此代码得到了结果。 int r = objcolor.R; int g = objcolor.G; int b = objcolor.B; int rgb = ((r & 0x0ff)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-01
      • 2022-11-21
      • 1970-01-01
      相关资源
      最近更新 更多