我的代码能够运行,但处理较大文件时需要花费更多时间。我想知道是否有人能够检查我的代码并提出任何改进建议,以使其更快。
目的:
这是为了扫描PDF文件并搜索QR码的位图图像,并返回其代码(解码)。
private void ScanQRPdf(string imagePath)
{
foreach (var item in Directory.GetFiles(imagePath))
{
if (Path.GetExtension(item).ToLower() == ".png")
{
Bitmap b = new Bitmap(imagePath);
try
{
QRCodeDecoder decoder = new QRCodeDecoder();
String decodedString = decoder.decode(new QRCodeBitmapImage(b));
rtbpdfData.Text += decodedString + "\n";
}
catch (Exception ex)
{
}
}
}
}
static void AddQRTag(PdfSharp.Drawing.XGraphics gfx, int xPosition, int yPosition, string QRdata, string HRdata)
{
gfx.DrawRectangle(XBrushes.White, xPosition, yPosition, xPosition + 55, yPosition + 85);
PdfSharp.Drawing.XImage xImage =
PdfSharp.Drawing.XImage.FromGdiPlusImage(BuildQR(QRdata.ToUpper(), 3,
QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC, 2, QRCodeEncoder.ERROR_CORRECTION.M));
gfx.DrawImage(xImage, xPosition + 5, yPosition + 5, xImage.PixelWidth * .8, xImage.PixelWidth * .8);
XFont font = new XFont("OCR B", 6);
XTextFormatter tf = new XTextFormatter(gfx);
tf.Alignment = XParagraphAlignment.Left;
XRect layout = new XRect(xPosition + 5, yPosition + 55, 55, 30);
tf.DrawString(HRdata.ToUpper(), font, XBrushes.Black, layout, XStringFormats.TopLeft);
}
catch{}
。 - H H