I am having trouble wrapping my head around this and wanted some input on this. So I am reading in a scanned PDF document that has a QR code in it which is always located on the top left corner of the document.
Due to the fact that scanning files might change the orientation of the document I am checking the top left corner of the document to see if it has the QR code and if not I will rotate the document and check the left corner again. Purpose of this because in the QR code is on the left top corner then the document is in proper format for my requirements.
How could I change my following code so that it gets the document checks for a QR code - if not found rotate the whole document check again and continue until the QR code has been found. Also should I just rotate by 90 in a loop rather than 90 - 180 - 270.
using (var fullImg = new Bitmap(workGif))
{
var bandImg = fullImg.Clone(new System.Drawing.Rectangle(0, 0, 375, 375), fullImg.PixelFormat);
Bitmap result = fullImg;
if (Process(bandImg) == null)
{
fullImg.RotateFlip(RotateFlipType.Rotate270FlipNone);
bandImg = fullImg.Clone(new System.Drawing.Rectangle(0, 0, result.Width, result.Height), fullImg.PixelFormat);
if (Process(bandImg) == null)
{
fullImg.RotateFlip(RotateFlipType.Rotate90FlipNone);
bandImg = fullImg.Clone(new System.Drawing.Rectangle(0, 0, result.Width, result.Height), fullImg.PixelFormat);
if (Process(bandImg) == null)
{
fullImg.RotateFlip(RotateFlipType.Rotate180FlipNone);
bandImg = fullImg.Clone(new System.Drawing.Rectangle(0, 0, result.Width, result.Height), fullImg.PixelFormat);
}
}
}
bandImg.Save(@"C:\NewImageTest.png");
string QRinfo = Process(bandImg);
MessageBox.Show(QRinfo);
}
Process Method I pass the image in this method to check and see if there is a QR code to be read.
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 null;
}
}
resultand where does it come from?