2013-03-07 75 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