Color Keys too large for System.Int32 ???
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--
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
But the function asks for a regular int, not unsigned, from what I can see.
0xFF000000 is by default an unsigned int, and if I put that in, the compiler cries:
E:\Starting C#\textureHandler.cs(46): Argument ''11'': cannot convert from ''uint'' to ''int''
--Vic--
0xFF000000 is by default an unsigned int, and if I put that in, the compiler cries:
E:\Starting C#\textureHandler.cs(46): Argument ''11'': cannot convert from ''uint'' to ''int''
--Vic--
So just cast it. The bit pattern is the same.
"Sneftel is correct, if rather vulgar." --Flarelocke
"Sneftel is correct, if rather vulgar." --Flarelocke
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--
(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--
did you read the error message? It''s telling you to use unchecked syntax while casting.
"Sneftel is correct, if rather vulgar." --Flarelocke
"Sneftel is correct, if rather vulgar." --Flarelocke
It says to do unchecked to override the overflow. Do I want to do that? If so, how do I do it?
--Vic--
--Vic--
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]
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]
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement