Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse this QR code, I don't know why #549

Open
moonlight4rr opened this issue Feb 17, 2024 · 1 comment
Open

Unable to parse this QR code, I don't know why #549

moonlight4rr opened this issue Feb 17, 2024 · 1 comment

Comments

@moonlight4rr
Copy link

moonlight4rr commented Feb 17, 2024

下载

I'm running the latest version 0.16.9 from NuGet.

  BarcodeReader reader = new BarcodeReader();
  reader.AutoRotate = true;
  reader.Options.TryInverted = true;
  reader.Options.TryHarder = true;
  reader.Options.PossibleFormats = new List<ZXing.BarcodeFormat>();
  reader.Options.PossibleFormats.Add(ZXing.BarcodeFormat.QR_CODE);
  var result = reader.Decode(bitmap);
@moonlight4rr
Copy link
Author

After compressing the image, it can be parsed. Is the image quality too high to be parsed?

BarcodeReader reader = new BarcodeReader();
reader.AutoRotate = true;
reader.Options.TryInverted = true;
reader.Options.TryHarder = true;
reader.Options.PossibleFormats = new List<ZXing.BarcodeFormat>();
reader.Options.PossibleFormats.Add(ZXing.BarcodeFormat.QR_CODE);
//compress pictures
bitmap = CompressImage(bitmap);
var result = reader.Decode(bitmap);

/// <summary>
/// compress pictures
/// </summary>
/// <param name="image"></param>
/// <param name="width">Target width</param>
/// <returns></returns>
public static Bitmap CompressImage(Bitmap srcBmp, int width)
{
    int srcWidth = srcBmp.Width;
    //if (srcWidth <= width)
    //{
    //    return srcBmp;
    //}
    int height = (int)(srcBmp.Height * (width / (double)srcWidth));
    Bitmap bmp = new Bitmap(width, height);
    using (Graphics gr = Graphics.FromImage(bmp))
    {
        gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
        gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
        //Setting to HighQualityBicubic cannot be resolved
        gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
        System.Drawing.Rectangle rectDestination = new Rectangle(0, 0, width, height);
        gr.DrawImage(srcBmp, rectDestination, 0, 0, srcBmp.Width, srcBmp.Height, GraphicsUnit.Pixel);
    }
    return bmp;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant