简体   繁体   English

创建 BGR555 颜色转换器时出现问题 (VB.NET)

[英]Problems creating a BGR555 color converter (VB.NET)

I've been trying to create a function for VB.NET, capable of converting Hexadecimal Color to BGR555 format.我一直在尝试为 VB.NET 创建一个 function,能够将十六进制颜色转换为 BGR555 格式。 As far as I've looked, there's only one function that does this on the inte.net, but it's done in JavaScript (more details: https://orangeglo.github.io/BGR555/ )据我所知,在 inte.net 上只有一个 function 这样做,但它是在 JavaScript 中完成的(更多细节: https://orangeglo.github.io/BGR555/

I even had help from some people in creating the function, but it still didn't turn out as expected.我什至在一些人的帮助下创建了 function,但结果仍然不如预期。 If anyone finds out why the result is different, I would be very grateful.如果有人发现结果不同的原因,我将不胜感激。

Practical example: The original function in JavaScript converted the value #FFFFFF to 7FFF (Big Endian).实际例子:原来JavaScript中的function将值#FFFFFF转换为7FFF (Big Endian)。 With the function I created together with others, it returns 2048 .使用我与其他人一起创建的 function ,它返回2048 https://i.stack.imgur.com/R8hSs.png https://i.stack.imgur.com/R8hSs.png

Not sure why your conversion function converts White ( RGB (255, 255, 255) ) or #FFFFFF (RGB) to 2048 in BGR555.不确定为什么您的转换 function 将白色 ( RGB (255, 255, 255) ) 或#FFFFFF (RGB) 转换为 BGR555 中的2048

Assuming 2048 is hexadecimal, the bits representation is 10000001001000假设2048是十六进制,则位表示为10000001001000
If it's decimal, the representation is 100000000000如果是十进制,则表示为100000000000
I don't know how you got there, it should be 111111111111111 .我不知道你是怎么到那里的,它应该是111111111111111

BGR555 is defined as BGR555 定义为

a sRGB format with 16 bits per pixel (BPP).每像素 16 位 (BPP) 的 sRGB 格式。
Each color channel (blue, green, and red) is allocated 5 bits per pixel (BPP).每个颜色通道(蓝色、绿色和红色)都分配了每像素 5 位 (BPP)。

In VB.NET it could be something like this:在 VB.NET 中可能是这样的:

Imports System.Drawing

' Get the Color value from its HTML representation
Dim rgb = ColorTranslator.FromHtml("#FFFFFF")

' Divide R, G and B values by 8 and shifts left by 0, 5 and 10 positions 
' (16 bit pixel, each color in 5 bits)
Dim colorBGR555 = CShort((rgb.R \ 8) + ((rgb.G \ 8) << 5) + ((rgb.B \ 8) << 10))
' Converts to string in Hex Format (Big Endian)  
Dim colorBGR555HexBE = colorBGR555.ToString("X2")

' Reverse the bytes (it's a Short value, two bytes) for its Little Endian representation
Dim bytes = BitConverter.GetBytes(colorBGR555).Reverse().ToArray()
Dim colorBGR555HexLE = BitConverter.ToInt16(bytes, 0).ToString("X2")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM