【问题标题】:drawing a rectangle for a bitmap clone为位图克隆绘制一个矩形
【发布时间】:2013-02-23 05:30:16
【问题描述】:

我有一个位图,我在其中克隆并指定了一个矩形 - 当前矩形具有特定的宽度和高度值,我用它们来检查矩形是否有 QR 码。我注意到这检查了左上角。我可以更改它以检查相同大小(宽度和高度)的右上角、右下角和左下角吗?

 Bitmap result = fullImg.Clone(new System.Drawing.Rectangle(0, 0, 375, 375), fullImg.PixelFormat);

非常感谢任何帮助。

for (int pg = 0; pg < inputDocument.PageCount; pg++)
            {

                string workGif = workingFilename.Replace(".pdf", string.Format(".{0}.gif", pg + 1));
                GhostscriptWrapper.GeneratePageThumb(workingFilename, workGif, pg + 1, 300, 300); // size (last two params) does not seem to have any effect
                using (var fullImg = new Bitmap(workGif))
                {  
                        Bitmap result = fullImg.Clone(new System.Drawing.Rectangle(0, 0, 375, 375), fullImg.PixelFormat);
                        string QRinfo = Process(result);
                        MessageBox.Show(QRinfo);

                        string[] qcode = QRinfo.Split('/');
                        string gid = qcode[qcode.Count() - 1];
                        Guid pgGuid = new Guid(gid);
                }        
            }

qr的处理方法

public string Process(Bitmap bitmap)
    {
        var reader = new com.google.zxing.qrcode.QRCodeReader();

        try
        {
            LuminanceSource source = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height);
            var binarizer = new HybridBinarizer(source);
            var binBitmap = new BinaryBitmap(binarizer);
            return reader.decode(binBitmap).Text;
        }
        catch (Exception e)
        {
            return e.Message;
        }
    }

【问题讨论】:

  • 用这个你能达到什么目的?一个矩形有一个 Point 和一个 Size,一个 Point 的计算总是考虑到左上角的位置。
  • @GuFigueiredo 我正在尝试找出一种方法来检测页面上的二维码,并根据其位置来旋转它,以便二维码位于左上角。如何在整个页面中查找二维码并找到要旋转的位置?
  • 您能提供更多信息吗?您有 Windows 窗体中的二维码还是 ASP.NET 页面?这些元素是如何加载到控件中的?
  • @GuFigueiredo 我为我的工作添加了更多代码,这是一个 Windows 窗体。基本上它是一个扫描的pdf,上面有一个二维码。我要扫描二维码并将文档正面朝上旋转,使二维码位于左上角。我真的很希望你能以任何方式帮助我,我已经思考了几个小时并在这个问题上工作了几个小时。谢谢!

标签: c# system.drawing bitmapimage


【解决方案1】:

如果二维码总是在角落,您可以使用图片框作为位图,然后使用 RotateFlip 方法对其进行旋转:

Bitmap bp = new Bitmap("myImage.jpg");
pictureBox1.Image = bp;
bp.RotateFlip(RotateFlipType.Rotate90FlipNone);
pictureBox1.Invalidate();

【讨论】:

  • 因为我没有使用图片框,也不会使用我可以继续使用旋转翻转?
  • 您可以使用 RotateFlip 进行测试。我认为会起作用,因为 RotateFlip 是 Bitmap 的一种方法,而不是 PictureBox。
  • 这可行,但在修复其旋转后让我回到原来的问题。它将原始图像传递给处理方法,而不是看起来像旋转的图像
猜你喜欢
  • 2020-04-26
  • 2013-09-03
  • 1970-01-01
  • 2018-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-09
相关资源
最近更新 更多