我遇到了麻烦,在这个问题上缠绕我的头,并希望对此进行一些输入。所以我正在阅读扫描的PDF文档,该文档中有一个QR码,它始终位于文档的左上角。创建一个循环,而不是重复if语句
由于扫描文件可能会更改文档的方向,因此我正在检查文档的左上角以查看它是否具有QR码,如果不是,我将旋转文档并再次检查左侧的角落。这样做的目的是因为QR码在左上角,所以文档的格式符合我的要求。
如何更改我的以下代码,以便它可以获取QR码的文档检查 - 如果未找到,请再次旋转整个文档检查并继续,直到找到QR码。还应我90在一个循环中只需旋转,而不是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);
}
过程方法 我通过在该方法的图像检查,看看是否有要被读取的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 null;
}
}
什么是结果?它从哪里来的? – cdhowie 2013-03-20 01:48:07
@cdhowie错过了放入 - 结果是整个文件页面的图像。 – Masriyah 2013-03-20 01:50:38