English 中文(简体)
C# 借鉴图像的红行动
原标题:C# redaction drawing on Image
  • 时间:2010-01-13 21:39:42
  •  标签:
  • c#

正在进行的是,需要从形象中汲取一个黑白。 我必须装上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
                            }
                        }
最佳回答

Bitmap newImage = new Bitmap(original.Width, original.Height);

页: 1

Bitmap newImage = new Bitmap(original);

This will make your newImage start with the contents of original. The difference will be that you will end up with newImage.PixelFormat == PixelFormat.Format32bppArgb, while I m assuming original.PixelFormat == PixelFormat.Format1bppIndexed. With PixelFormat.Format32bppArgb, you can create a Graphics object; you cannot with PixelFormat.Format1bppIndexed.

问题回答

你们应当努力:

original = (Bitmap)System.Drawing.Image.FromFile(coveted, true); 
using (Graphics g = Graphics.FromImage(original)) 
{ 
  using (SolidBrush brush = new SolidBrush(Color.Black)) 
  { 
    g.FillRectangle(brush, new Rectangle(x1value, y1value, x3value, y3value)); 
  } 
} 
pictureBox1.Image = original;

你们不要在新时代画出原始形象。

为此:

g.DrawImageUnscaled(original, 0, 0);

此外,我认为,它将做如下工作:它能更好地利用援助团,然后显示它会加以筛选。 或许 然而,我错了。

using (Graphics g = Graphics.FromImage(newImage))
    {
         g.DrawImageUnscaled(original, 0, 0);

         using (SolidBrush brush = new SolidBrush(Color.Black))
         {
                g.FillRectangle(brush, new Rectangle(x1value, y1value, x3value, y3value));
          }
    }
pictureBox1.Image = newImage;

我先测试了上述代码。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签