Re: convert Uint32 to System.drawing.color

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Yaniv wrote:
Göran Andersson כתב:
Yaniv wrote:
Hi

How can I convert Uint32 variable to System.drawing.color ??

Thanks in advanced
Yaniv

If the integer is representing an argb (alpha+rgb) value, then you can
use the Color.FromArgb(int) method. If it only represents an rgb value,
then you can use Color.FromArgb(int, int), where the first integer is
the alpha value, which you should set to 255 to get a solid color.

--
Göran Andersson
_____
http://www.guffa.com

Hi

The first option you wrote is not working since the value is Uint32
and not integer as you wrote (I'v got the message "Value of type
'System.UInt32' cannot be converted to 'Integer')

You can just cast the UInt32 to an Int32:

Color color = Color.FromArgb((int)colorValue);

The second option doesn't exist in VB.NET at all (Anyway I can't
convert Uint32 to int.....)

Yes, you are right. There is no such overload to the method. I was thinking of the Color.FromArgb(int, Color) overload:

Color color = Color.FromArgb(255, Color.FromArgb((int)colorValue));

actually I dont know if the Uint32 color is represent argb color or
only rgb color...

That will be obvious when you try to use it. If it's an rgb value the top eight bits will be zero, which when used as alpha will make a completely transparent color.

--
Göran Andersson
_____
http://www.guffa.com
.



Relevant Pages

  • Re: convert Uint32 to System.drawing.color
    ... If it only represents an rgb value, ... The first option you wrote is not working since the value is Uint32 ... There is no such overload to the method. ... If it's an rgb value the top eight bits will be zero, which when used as alpha will make a completely transparent color. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Luminance calculation
    ... For RGB (without alpha) I use the gray formula for RGB whichs works ... Because compositing and luminance ...
    (comp.graphics.algorithms)
  • Re: 16 bit s/w nach Falschfarben und =?ISO-8859-15?Q?zur=FCck?=
    ... 3x8bit RGB Farbe. ... Wie sieht's mit ARGB aus, d.h. RGB mit Alpha? ...
    (de.sci.physik)
  • Re: texture filtering and transparency
    ... texure format with 24 bit RGB, so I would have to use 15 bit RGB which is also not an optimal solution. ... you can always use alpha testing to discard pixels instead of blending them. ...
    (microsoft.public.win32.programmer.directx.graphics)