Search code examples
c#system.drawingbitmapimage

drawing a rectangle for a bitmap clone


I have a bitmap in which i clone and specify a rectangle - the current rectangle has certain width and height values which i've used for checking the rectangle for a QR code. I noticed this checks the top left corner. I would i be able to alter this to check for top right corner, bottom right and left corners of the same size(width and height)?

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

Any help is greatly appreciated.

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

Process Method for 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;
        }
    }

Solution

  • If the QRCodes are ALWAYS on the corners, you can use a picturebox for the Bitmap, and then rotate it using the RotateFlip method:

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