嘿嘿,我正在把图像转换为 ASCII 图像。为此,我加载图像,在每个像素上使用 getPixel(),然后将具有该颜色的字符插入到 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 确实返回正确的颜色,但文本仅以黑色结束。如果我改变
这
richTextBox1.SelectionColor = bmBild.GetPixel(x, y);
对此
richTextBox1.SelectionColor = Color.Red;
它工作正常。
为什么我没有得到正确的颜色?
(我知道它没有正确地做新的线路,但我想我会先搞清楚这个问题的根源。)
谢谢