Jump to content
Paint.NET 5.1 is now available! ×

Recommended Posts

Posted

I probably should know this, but is there any compact way of initializing a 2D array of ColorBgra values?

 

Like this, but with ColorBgras: int[,] = { {0, 1}, {2, 3}, (4, 5} };

 

Posted
2 hours ago, BoltBait said:

Easy:

 

But I need it for arbitrary colors, not jut predefined.

 

EDIT: For some reason, right or wrong, I was thinking that you can only use constants in array initializers, not methods like ColorBgra.FromBgra(0, 1, 2, 3). Now I'm not so sure. I'll look it up tomorrow. I tend to forget those details on things I haven't used for a while.

 

Also, even that wouldn't work out all that well for what I'm thinking about. It's a rather large array, so having each entry require such a long string would take up a lot of space. I think maybe the best thing is to just use an array of unsigned ints, convert it, element by element, to a ColorBgra array in the program, then set the int array to null and let the garbage collector handle it. Far from elegant, but it would probably work okay for my idea.

 

Oh, and thanks for the answer to a question I probably should have thought a little more about before bothering people with.

 

EDIT 2: Pointlessly driving this thing into the ground, I think what I was remembering with regard to initializing variables with only constants has to do with constant variables -- or something like that. Is it any wonder I have to keep a C# reference book handy when writing programs?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...