为位图克隆绘制矩形

本文关键字:绘制 位图 | 更新日期: 2023-09-27 18:02:44

我有一个位图,我克隆并指定一个矩形-当前矩形有一定的宽度和高度值,我用来检查矩形的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;
        }
    }

为位图克隆绘制矩形

如果QRCodes总是在角上,你可以为位图使用一个图片框,然后使用RotateFlip方法旋转它:

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