C ++函数将转换24位彩色像素 [英] C++ function that will convert a 24bit color pixel

查看:60
本文介绍了C ++函数将转换24位彩色像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,


所以我的一位朋友给了我这个问题。没有信息或turtorial。只是一张纸和一支铅笔。毋庸置疑,它并不顺利,现在我的大脑想知道答案。我将尝试尽可能地记住这个问题。


编写一个C ++函数,它将转换为以下格式的24位彩色像素


RGB24(8:8:8)

成16bit彩色像素

RGB16(5:6:5)


确保完成所有正确的变量检查。


i从未在这样的任何事情上工作过,所以我会喜欢任何反馈。


谢谢!

Hey guys,

so i was given this question by one of my dads friends. With no information or turtorial. Just a paper and a pencil. Needless to say, it did not go well, and now my brain want to know the answer. I will try and remember the question as best i can.

Write a C++ function that will convert a 24bit color pixel in the follow format

RGB24(8:8:8)

into a 16bit color pixel

RGB16(5:6:5)

ensure that all the proper variable checking is done.

i have never worked on anything like this, so i would love any feed back.

Thanks!

推荐答案

24位R是8位,可以保存0-255。

16位R是5位,可以保持0-31的值。


您可能会考虑(24位R)%31来获得16- bit R。
The 24-bit R is 8 bits and that can hold a value 0-255.
The 16-bit R is 5 bits and that can hold a value 0-31.

You might think about (24-bit R) % 31 to get the 16-bit R.


这是什么意思,当你有


RGB24(8:8:8)


i意思是,我可以假设这意味着8red 8绿色8蓝色。


但我怎么能抓住红色的值?来自RGB


RGB24 [0] = RGB16 [0]%31?
what does it mean, when you have

RGB24(8:8:8)

i mean, i can assume that this means 8red 8 green 8 blue.

but how would i grab the value of red? from RGB

RGB24[0] = RGB16[0]%31?



what是什么意思,当你有


RGB24(8:8:8)


i意思是,我可以认为这意味着8red 8 green 8蓝色。


但我怎么能抓住红色的价值?来自RGB


RGB24 [0] = RGB16 [0]%31?
what does it mean, when you have

RGB24(8:8:8)

i mean, i can assume that this means 8red 8 green 8 blue.

but how would i grab the value of red? from RGB

RGB24[0] = RGB16[0]%31?



简单。


24位像素用32位整数表示。


格式为0x00RRGGBB(如果使用RGBA格式,00将变为AA),那么您将使用哪个逻辑运算符仅提取部分格式?

Simple.

24bit pixel is represented with 32 bit integer.

in this format 0x00RRGGBB (00 becomes AA if you are using RGBA format),so which logical operator are you going to use to extract only parts of it?


这篇关于C ++函数将转换24位彩色像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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