【发布时间】:2011-02-08 22:46:59
【问题描述】:
嘿嘿,我正在把图像转换成 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;
效果很好。
为什么我没有得到正确的颜色?
(我知道它没有正确执行新行,但我想我会先深入了解这个问题。)
谢谢
【问题讨论】:
标签: c# colors richtextbox getpixel