如何在c#中将RGB555转换为RGB888?

Ori*_*guy 3 c# rgb

我需要将16位XRGB1555转换为24位RGB888.我的功能如下所示,但它并不完美,即0b11111的值将给出248作为像素值,而不是255.此函数适用于little-endian,但可以很容易地修改为big-endian.

public static Color XRGB1555(byte b0, byte b1)
{ 
    return Color.FromArgb(0xFF, (b1 & 0x7C) << 1, ((b1 & 0x03) << 6) | ((b0 & 0xE0) >> 2), (b0 & 0x1F) << 3); 
}
Run Code Online (Sandbox Code Playgroud)

任何想法如何使其工作?

stu*_*ith 7

您通常会将最高位复制到最低位,因此如果您有五位,如下所示:

Bit position: 4 3 2 1 0
Bit variable: A B C D E
Run Code Online (Sandbox Code Playgroud)

您可以将其扩展为8位:

Bit position: 7 6 5 4 3 2 1 0
Bit variable: A B C D E A B C
Run Code Online (Sandbox Code Playgroud)

这样,所有零都保留为全零,所有零都变为全部,并且值之间的值适当.

(注意,A,B,C等不应该是十六进制数字 - 它们是表示单个位的变量).