簡體   English   中英

為位圖克隆繪制一個矩形

[英]drawing a rectangle for a bitmap clone

我有一個位圖,在其中克隆並指定一個矩形-當前矩形具有某些寬度和高度值,這些值已用於檢查該矩形的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;
        }
    }

如果QRCode總是在拐角處,則可以將圖片框用於位圖,然后使用RotateFlip方法對其進行旋轉:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM