2013-03-07 76 views
0

我有一个位图,其中我克隆并指定一个矩形 - 当前矩形具有一定的宽度和高度值,我用它来检查QR码的矩形。我注意到这个检查左上角。我可以改变这个来检查右上角,右下角和左下角的相同尺寸(宽度和高度)?绘制矩形的位图克隆

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

任何帮助,非常感谢。对于QR

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); 
       }   
      } 

加工方法

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; 
     } 
    } 
+0

你会用这个来达到什么目的?一个矩形有一个Point和一个Size,并且Point总是考虑左上角的位置来计算的。 – GuFigueiredo 2013-03-07 20:29:48

+0

@GuFigueiredo我想找出一种方法来检测页面上的二维码,并根据它的位置我想旋转它,使二维码在左上角。我如何查找整个页面中的qr代码并找到它的位置来旋转? – Masriyah 2013-03-07 20:32:22

+0

你能提供更多信息吗?您在Windows窗体中具有qr代码还是ASP.NET页面?这些元素如何加载到控件中? – GuFigueiredo 2013-03-07 20:41:04

回答

0

如果QRCodes总是在角落,你可以使用位图一个PictureBox,然后旋转使用RotateFlip方法是:

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

由于我没有使用picturebox,也不会使用一个我可以继续使用rotateflip? – Masriyah 2013-03-07 21:32:47

+0

您可以使用RotateFlip进行测试。我认为会工作,因为RotateFlip是一个位图的方法,而不是PictureBox。 – GuFigueiredo 2013-03-07 21:45:48

+0

这个工程,但固定它的旋转后,带我回到我原来的问题。它将原始图像传递给处理方法,而不是旋转它看起来像 – Masriyah 2013-03-07 21:54:41