C# Problem with getPixel & setting RTF text colour accordingly
- by m3n
Heyo, I'm messing with converting images to ASCII ones. For this I load the image, use getPixel() on each pixel, then change insert a character with that colour into a richTextBox.
Bitmap bmBild = new Bitmap(openFileDialog1.FileName.ToString()); // valid image
int x = 0, y = 0;
for (int i = 0; i <= (bmBild.Width * bmBild.Height - bmBild.Height); i++)
{
// Ändra text här
richTextBox1.Text += "x";
richTextBox1.Select(i, 1);
if (bmBild.GetPixel(x, y).IsKnownColor)
{
richTextBox1.SelectionColor = bmBild.GetPixel(x, y);
}
else
{
richTextBox1.SelectionColor = Color.Red;
}
if (x >= (bmBild.Width -1))
{
x = 0;
y++;
richTextBox1.Text += "\n";
}
x++;
}
GetPixel does return the correct colour, but the text only end up black. If I change
this
richTextBox1.SelectionColor = bmBild.GetPixel(x, y);
to this
richTextBox1.SelectionColor = Color.Red;
It works fine.
Why am I not getting the right colours?
(I know it doesn't do the new lines properly, but I thought I'd get to the bottom of this issue first.)
Thanks