Campare COLORREF和Char [英] Campare COLORREF and Char

查看:59
本文介绍了Campare COLORREF和Char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

有人可以告诉我如何将COLORREF转换为char吗?

我已经看到了将它们转换为CString的示例.

COLORREF Color;
char Temp[256];
Color = GetPixel(MemDC,Point2.x,Point2.y);



如何获取颜色"到温度"作为十六进制值?

在此先感谢

是的.

我正在尝试从不同的像素获得以下语句.

 如果(颜色1 == " && Color2 == " 
        && Color3 == " && Color4 == " 
        && Color5 == " )



除了将COLORREF转换为字符串或char之外,我还能设法做到这一点.

我是新来的,试图对没有注释的代码进行调试.

解决方案

COLORREF是一个普通的长字,它是类型定义的.

我认为你的意思是:

 COLORREF颜色;
字符 Temp [ 256 ];
颜色= GetPixel(MemDC,Point2.x,Point2.y);
sprintf_s(Temp," ,彩色); 


COLORREF是一个32位无符号整数的typedef.

因此,可以像下面的示例一样比较值,而不是比较字符串:

if (Color1 == 0x414141 && Color2 == 0x3a3a3a
        && Color3 == 0xd2d2d2 && Color4 == 0
        && Color5 == 0 )



这会将Colour1,Color2和Color3与三种不同的灰色阴影进行比较(红色,绿色,蓝色这三个值相同的任何颜色都会给出灰度结果).


Hello,

Can someone pls tell me how do I convert COLORREF to char?

I have seen examples to convert them into CString.

COLORREF Color;
char Temp[256];
Color = GetPixel(MemDC,Point2.x,Point2.y);



How do I get Color to Temp as a hex value?

Thanks in Advance

Yes It is.

I am trying to achive the following statement from different pixels.

if (Color1 == "414141" && Color2 == "3a3a3a"
        && Color3 == "d2d2d2" && Color4 == "0"
        && Color5 == "0" )



How else but to either turn the COLORREF into a string or char will I manage to achive that.

I am new at this and trying to degug a code, that was left behind with no comments.

解决方案

COLORREF is a plain long which is typedef''ed. Use sprintf with ''x'' for format specifier.


I think you mean this:

COLORREF Color;
char Temp[256];
Color = GetPixel(MemDC,Point2.x,Point2.y);
sprintf_s(Temp, "%06x", Color);


COLORREF is, as people have said, a typedef of a 32-bit unsigned integer.

So instead of comparing strings, as your example, you can compare values like this:

if (Color1 == 0x414141 && Color2 == 0x3a3a3a
        && Color3 == 0xd2d2d2 && Color4 == 0
        && Color5 == 0 )



This compares Colour1, Color2 and Color3 to three different grey shades (any colour where the three values - Red, Green, Blue - are the same give a greyscale result).


这篇关于Campare COLORREF和Char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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