Reputation: 127543
I am doing some reverse engineering work on a program. One of the things I am trying to pull out of the old data is a color that was chosen from the below color pallet
The way the old software is refrencing the color is by the index in the pallet (so 0 is white, 1 is yellow, 2 is orange, and so on). Is the above pallet a standard layout of some type?
What my best hope is to find some class built in to .NET where I could pass the same index number in and get the color back, however I don't have high hopes for finding something that nice.
Besides using paint and an eyedropper to manually map out the whole table is there any option to make this easier on me?
Upvotes: 0
Views: 1222
Reputation: 887225
You can write some code that reads that bitmap and examines the pixels to build the palette of colors in the bitmap you've extracted.
Upvotes: 1
Reputation: 127543
I ended up using SLaks suggestion and just looped over the image and read the pixel values from the center of each square. Here is quick proof of concept test I ran that loaded all of the colors in to a TableLayoutPanel
and it worked perfectly.
private void button1_Click(object sender, EventArgs e)
{
string pngPath = @"E:\Color Pallet.png";
tableLayoutPanel1.Controls.Clear();
using (var bitmap = new Bitmap(pngPath))
{
for (int i = 0; i < 256; i++)
{
var color = bitmap.GetPixel(5 + (10*(i%16)), 5 + (10*(i/16)));
tableLayoutPanel1.Controls.Add(new Panel {Dock = DockStyle.Fill, BackColor = color}, i % 16, i / 16);
}
}
@SLaks, if you post your own answer I will delete mine and accept yours.
Upvotes: 1
Reputation: 264
This is a 16 x 16 = 256 palette. The old Software possibly stored this palette in a gif-file. You could build an array of hex values from this palette (hard coded or at runtime).
The first row is a "useful"-colors row.
Row two to eight shifts hue values from hue 338° to hue 335°.
Row nine to fifteen show (7) tints and (8) shades (HSB color model) of hue 0°, 30°, 60°, 116°, 180°, 230° and 300°.
Last row is obviously a grayscale.
I don't think this is a standard layout. If you want an exact value, you need to use the eyedropper...
Upvotes: 1