Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
init returns the background color of a world as a uint. How do I convert this value back to hex code or rgb?
example, #000080 becomes 4278190208 edit: how do I convert 4278190208 back to #000080
Offline
capasha has it somewhere in his code, check his website capasha.com
if you can read this....good for you
Offline
I'm not quite sure what I'm looking for here. Is it some source code for a converter?
Offline
its in his minimap project iirc but im not sure
if you can read this....good for you
Offline
public static Color UIntToColor(uint color)
{
byte a = (byte)(color >> 24);
byte r = (byte)(color >> 16);
byte g = (byte)(color >> 8);
byte b = (byte)(color >> 0);
return Color.FromArgb(a, r, g, b);
}
Color color UintToColor(4291715791);
var hex = "#" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
This code is the code to make hex colors.
Offline
This integer is the decimal form of an ARGB color (A being alpha, coding the transparency is set at 255).
So if you transpose 4278190208 to hexadecimal, you'll find #FF000080
Offline
Thank you very much
Offline
public static Color UIntToColor(uint color) { byte a = (byte)(color >> 24); byte r = (byte)(color >> 16); byte g = (byte)(color >> 8); byte b = (byte)(color >> 0); return Color.FromArgb(a, r, g, b); } Color color UintToColor(4291715791); var hex = "#" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
This code is the code to make hex colors.
Or you could just use this to do the conversion from uint to Color:
Color.FromArgb(unchecked((int)m.GetUInt(19)));
But depending on your build settings, unchecked is probably used by default, in which case, you can use:
Color.FromArgb((int)m.GetUInt(19));
EDIT:
But to get to the hexadecimal value, I would use this:
"#" + m.GetUInt(19).ToString("X8");
EDIT 2: Forgot that you probably don't want the alpha value in there
"#" + (m.GetUInt(19) & 0xFFFFFF).ToString("X6");
Offline
[ Started around 1732215696.644 - Generated in 0.063 seconds, 12 queries executed - Memory usage: 1.43 MiB (Peak: 1.55 MiB) ]