如何在c#中从RGB555转换为RGB888? [英] How to convert from RGB555 to RGB888 in c#?

查看:86
本文介绍了如何在c#中从RGB555转换为RGB888?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to convert 16-bit XRGB1555 into 24-bit RGB888. My function for this is below, but it's not perfect, i.e. a value of 0b11111 wil give 248 as the pixel value, not 255. This function is for little-endian, but can easily be modified for 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); 
}

任何想法如何使它工作?

Any ideas how to make it work?

推荐答案

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

You would normally copy the highest bits down to the bottom bits, so if you had five bits as follows:

Bit position: 4 3 2 1 0
Bit variable: A B C D E

您可以将其扩展为八位:

You would extend that to eight bits as:

Bit position: 7 6 5 4 3 2 1 0
Bit variable: A B C D E A B C

这样,所有零仍然是全零,所有 1 都变成全 1,并且中间的值会适当地缩放.

That way, all zeros remains all zeros, all ones becomes all ones, and values in between scale appropriately.

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

(Note that A,B,C etc aren't supposed to be hex digits - they are variables representing a single bit).

这篇关于如何在c#中从RGB555转换为RGB888?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆