正在进行的是,需要从形象中汲取一个黑白。 我必须装上tif子,然后展示一个黑箱。 我得到了一些法典的帮助,但总是发现错误: 不能用具有指数化的六氯苯形式的形象来制造图象物体。
因此,我不得不以借方形式阅读,但当我显示盒子时,它会毁掉箱子。 完整地在原形象的所有黑色部分展示画面。 如果有人能帮助我,一米人会错失,那将非常麻烦。
Bitmap original = (Bitmap)System.Drawing.Image.FromFile(coveted, true);
Bitmap newImage = new Bitmap(original.Width, original.Height);
pictureBox1.Image = newImage;
using (Graphics g = Graphics.FromImage(pictureBox1.Image))
{
using (SolidBrush brush = new SolidBrush(Color.Black))
{
g.FillRectangle(brush, new Rectangle(x1value, y1value, x3value, y3value));
}
}
我不敢确定我如何能够使这一点更加明确。 发生的情况是,我没有支持。 因此,我不得不把它改成一个比图,以便我实际上能够把它 draw。 然后,我需要在一个图片箱中展示这种红act的形象(原来的红action)。 上文守则的内容一旦完成,即是一个没有原始形象的黑箱。
我认为,我对使用从下游到下游的“比特图”有点。 任何人都知道这一点?
Thanks to all the help from STO members!! heres the correct code for redacting images if you encounter the error "A Graphics object cannot be created from an image that has an indexed pixel format.". if you re given the redacted starting points (obviously you have to make the Regex work to your situation):
//Regex for pulling points from a file
string x1 = x1 = Regex.Match(l, @"
(d+)
(d+)").Groups[2].Value;
string y1 = y1 = Regex.Match(l, @"
(d+)
(d+)
(d+)").Groups[3].Value;
string x2 = x2 = Regex.Match(l, @"
(d+)
(d+)
(d+)
(d+)").Groups[4].Value;
string y2 = y2 = Regex.Match(l, @"
(d+)
(d+)
(d+)
(d+)
(d+)").Groups[5].Value;
string x3 = x3 = Regex.Match(l, @"
(d+)
(d+)
(d+)
(d+)
(d+)
(d+)").Groups[6].Value;
string y3 = y3 = Regex.Match(l, @"
(d+)
(d+)
(d+)
(d+)
(d+)
(d+)
(d+)").Groups[7].Value;
{
//convert string to int for redacted points
int x1value = Convert.ToInt32(x1);
int y1value = Convert.ToInt32(y1);
int x3value = Convert.ToInt32(x3);
int y3value = Convert.ToInt32(y3);
{
//BEGIN Workaround for indexed pixels
Bitmap original = (Bitmap)System.Drawing.Image.FromFile(YOURFILE, true);
Bitmap newImage = new Bitmap(original);
pictureBox1.Image = newImage; //END Workaround for indexed pixels
using (Graphics g = Graphics.FromImage(pictureBox1.Image)) //start redaction
{
using (SolidBrush brush = new SolidBrush(Color.Black))
{
g.DrawImageUnscaled(newImage, 0,0);
g.FillRectangle(brush, new Rectangle(x1value, y1value, x3value, y3value));
}
} //End Redaction
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; //Resized to fit into a static picturebox
}
}