Hello, I have recently needed a converter to hexadecimal from colored images. This plugin is used for sprite development on the ti-84 graphing calculator. I surfed the internet and couldn't find what I needed, so I decided to write a plugin on paint.net that will process my selection and display the output. Here's my progress, it currently is functional however it is conditional. It only properly works when my selection is 8x8, i am aware that i can put it in try and catch i will for sure implement that later, I want to focus on the things that matter now.
bool done = false;
void Render(Surface dst, Surface src, Rectangle rect)
{
Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
ColorBgra CurrentPixel;
string[,] binary1 = new string[8,8];
string[,] binary2 = new string[8,8];
int xx;
int yy = 0;
for (int y = selection.Top; y < selection.Bottom; y++)
{
xx=0;
if (IsCancelRequested) return;
for (int x = selection.Left; x < selection.Right;x++)
{
CurrentPixel = src[x,y];
int rgb = (CurrentPixel.R+CurrentPixel.G+CurrentPixel.B)/3;
if(rgb >= 0 && rgb < 64)
{
binary1[xx,yy] = "1";
binary2[xx,yy] = "1";
}
else if(rgb >= 64 && rgb < 128)
{
binary1[xx,yy] = "1";
binary2[xx,yy] = "0";
}
else if(rgb >= 128 && rgb < 192)
{
binary1[xx,yy] = "0";
binary2[xx,yy] = "1";
}
else if(rgb >= 192 && rgb < 256)
{
binary1[xx,yy] = "0";
binary2[xx,yy] = "0";
}
dst[x,y] = CurrentPixel;
xx++;
}
yy++;
}
if(done == false)
{
string line;
string hex = "[";
for(int y = 0; y < 8; y++)
{
line = "";
for(int x = 0; x < 8; x++)
line += binary1[x,y];
hex += ConvertHex(line);
}
hex += "][";
for(int y = 0; y < 8; y++)
{
line = "";
for(int x = 0; x < 8; x++)
line += binary2[x,y];
hex += ConvertHex(line);
}
hex += "]";
System.IO.File.WriteAllText(@"C:\Users\user\Desktop\Dota Duelz\hex.txt", hex);
done = true;
}
}
string ConvertHex(string strBinary)
{
string hex = Convert.ToInt32(strBinary,2).ToString("X");
if(hex.Length == 1)
hex = "0" + hex;
return hex;
}
Keep in mind this is the first plugin i write on paint.net, so it probably isn't the most efficient way to do this. Now my question is: what is a good way to display the output string "hex" to the user? I am currently writing to a file. Coming from java development I don't know the tools i can use to do these operations. I tried to display a message box but it seems to open it 8 times and that's why i tried implementing the Boolean done so i make sure it runs only once, but i am not sure why it didn't work.
EDIT:
Forgot to add a visual example of what it does:
It starts with the first image, i have to manually select 8 x 8 pixels and run the program to generate these four pairs hexs
[04050B3434742EEC][070E1A3B166E655B]
[20F0782C0A1E3577][E0A090BC3E34771E]
[5455D4F4CA5F7B00][F9FAF3CFFD6E6A00]
[1B9B1B3733FBFE00][0E2FFF5B777B3200]
and using this website, I am able to see the images visually
http://clrhome.org/pix/