簡體   English   中英

創建 BGR555 顏色轉換器時出現問題 (VB.NET)

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

我一直在嘗試為 VB.NET 創建一個 function,能夠將十六進制顏色轉換為 BGR555 格式。 據我所知,在 inte.net 上只有一個 function 這樣做,但它是在 JavaScript 中完成的(更多細節: https://orangeglo.github.io/BGR555/

我什至在一些人的幫助下創建了 function,但結果仍然不如預期。 如果有人發現結果不同的原因,我將不勝感激。

實際例子:原來JavaScript中的function將值#FFFFFF轉換為7FFF (Big Endian)。 使用我與其他人一起創建的 function ,它返回2048 https://i.stack.imgur.com/R8hSs.png

不確定為什么您的轉換 function 將白色 ( RGB (255, 255, 255) ) 或#FFFFFF (RGB) 轉換為 BGR555 中的2048

假設2048是十六進制,則位表示為10000001001000
如果是十進制,則表示為100000000000
我不知道你是怎么到那里的,它應該是111111111111111

BGR555 定義為

每像素 16 位 (BPP) 的 sRGB 格式。
每個顏色通道(藍色、綠色和紅色)都分配了每像素 5 位 (BPP)。

在 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