creating a mask for a color (uint vs int)

I

ivan.svaljek

When i try to use a blue mask for a random color like this:

Color.FromArgb( myrand.next() & 0xff0000ff )

I get an error: 0xff0000ff can't be converted to int.

Apparently maximum value for int32 is 7fffffff, so how am I to set the
alpha part to ff ?
 
M

Mattias Sjögren

When i try to use a blue mask for a random color like this:
Color.FromArgb( myrand.next() & 0xff0000ff )

I get an error: 0xff0000ff can't be converted to int.

You can cast to int in an unchecked context:

unchecked((int)0xff0000ff)


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top