Archived

This topic is now archived and is closed to further replies.

Color Keys too large for System.Int32 ???

This topic is 5111 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

To quote the DX SDK for the TextureLoader.FromFile method: colorKey System.Int32. [in] An Int32 value to replace with transparent black, or 0 to disable the color key. This is always a 32-bit ARGB color that is independent of the source image format. Alpha is significant, and usually should be set to FF for opaque color keys. For example, for opaque black, the value is equal to 0xFF000000. So I thought I could pass 0xFF000000 as the parameter for colorKey. But nope, the compiler cries that I''m trying to pass a uint and the function takes an int. So I convert it to an int, and the value is too large. Heh, come to find that the 0xAARRGGBB holds a little over 4 billion possible values. That''s a little too large for a System.Int32. Just as a test, I did Color.FromArgb(255,0,0,0).ToArgb() which compiled fine, but black wasn''t transparent. Anyone had this prob before, or even better, a solution? --Vic--

Share this post


Link to post
Share on other sites
quote:

Heh, come to find that the 0xAARRGGBB holds a little over 4 billion possible values. That''s a little too large for a System.Int32

No it isn''t. The maximum value for an unsigned 32-bit integer is 4294967295.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
First, I tried casting as follows

(int)0xFF000000, resulting in

E:\Starting C#\textureHandler.cs(46): Constant value ''4278190080'' cannot be converted to a ''int'' (use ''unchecked'' syntax to override)


Then I tried

Convert.ToInt32(0xFF000000)

Resulting in an unhandled Exception. Basically, an overflow. Value was too large for an Int32.

The bottom line is that 0xFF000000 is too big to fit in a signed int32, but the function doesn''t accept unsigned ints. Yet, the SDK itself gives the example of passing this too large 0xFF000000 (opaque black) as an example value. Is this some kind of bug? I doubt it, considering loading textures is a pretty common thing.

--Vic--

Share this post


Link to post
Share on other sites
No errors doing that, but I don't get the black being transparent.

Anyone else? The bottom line is why would the SDK tell you to pass 0xff000000 as is when that value doesn't work?

--Vic--

As a side note, I did create a blue bitmap, and changed the color key to Color.Blue.ToArgb(), and it worked perfectly. Maybe there is something specifically with the color black? I double and triplechecked my bitmaps so I know I'm using pure black.

[edited by - Roof Top Pew Wee on December 13, 2003 3:57:37 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Roof Top Pew Wee
why would the SDK tell you to pass 0xff000000 as is when that value doesn''t work?


The SDK explains functions in terms of many languages. Did you actually see a code fragment written in C# that mentions that value?


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
Yes! I''m having that same problem. The MDX 9 docs are worthless. I have no idea how to make it work.

Sorry, that was probably a little unhelpful. Still, if anyone out there knows the answer, I''d also be interested!


----------------------------------------
Let be be finale of seem, seems to me.
----------------------------------------

Coding:
http://www.stanford.edu/~jjshed/coding

Miscellany:
http://www.stanford.edu/~jjshed

Share this post


Link to post
Share on other sites