Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I tried to convert COLORREF to int but I don't find the correct way..

What I have tried:

I tried to search on internet, but I don't find the correct way
Posted
Comments
jeron1 16-Apr-24 10:14am    
Have you tried casting it? Something like,

int x = (int) dwValue;

COLORREF (Windef.h) - Win32 apps | Microsoft Learn[^]. As you can see it is defined as a DWORD (32 bits) so itis already an integer value.
 
Share this answer
 
Comments
CPallini 19-Apr-24 10:36am    
Indeed.
The conversion is as easy as already answered but you need to take care when making it to a COLORREF again. You need the same byte order and the same color depth.
When you mismatch it the colors are weirdly changed.

To better learn about working with images you should read the CXimage article and dig through the sample code. You have to love it. ;-)
 
Share this answer
 
Comments
0x01AA 19-Apr-24 11:34am    
Quote: "The conversion is as easy as already answered but you need to take care when making it to a COLORREF again"

Nope:
COLREF do have always the byte order BGR (ABGR), and assigning it to and from an int does note change it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900