Official Everybody Edits Forums

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.

#1 2015-05-28 14:58:19, last edited by kurtv13 (2015-05-29 03:28:46)

kurtv13
Member
From: Everywhere
Joined: 2015-04-24
Posts: 59

[SOLVED] Getting background color from "init"

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


Pfffffttt

Offline

#2 2015-05-28 15:26:02

ewoke
Member
Joined: 2015-02-20
Posts: 412

Re: [SOLVED] Getting background color from "init"

capasha has it somewhere in his code, check his website capasha.com


if you can read this....good for you

Offline

#3 2015-05-28 15:31:46

kurtv13
Member
From: Everywhere
Joined: 2015-04-24
Posts: 59

Re: [SOLVED] Getting background color from "init"

I'm not quite sure what I'm looking for here. Is it some source code for a converter? //forums.everybodyedits.com/img/smilies/smile


Pfffffttt

Offline

#4 2015-05-28 15:37:09

ewoke
Member
Joined: 2015-02-20
Posts: 412

Re: [SOLVED] Getting background color from "init"

its in his minimap project iirc but im not sure


if you can read this....good for you

Offline

#5 2015-05-28 17:02:39, last edited by capasha (2015-05-28 17:11:19)

capasha
Member
Joined: 2015-02-21
Posts: 4,066

Re: [SOLVED] Getting background color from "init"

        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

Wooted by:

#6 2015-05-28 17:03:11

TiKen
Member
Joined: 2015-02-24
Posts: 298

Re: [SOLVED] Getting background color from "init"

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 //forums.everybodyedits.com/img/smilies/smile

Offline

Wooted by:

#7 2015-05-29 02:49:33

kurtv13
Member
From: Everywhere
Joined: 2015-04-24
Posts: 59

Re: [SOLVED] Getting background color from "init"

Thank you very much //forums.everybodyedits.com/img/smilies/big_smile


Pfffffttt

Offline

#8 2015-05-30 04:10:51, last edited by rubixguy (2015-05-30 04:28:37)

rubixguy
Member
Joined: 2015-03-19
Posts: 27

Re: [SOLVED] Getting background color from "init"

capasha wrote:
        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");

QY3OIOZ.png

Offline

Wooted by:
rubixguy1432955451508383

Board footer

Powered by FluxBB

[ Started around 1732215696.644 - Generated in 0.063 seconds, 12 queries executed - Memory usage: 1.43 MiB (Peak: 1.55 MiB) ]