/// <summary>
/// 生成QR码
/// </summary>
/// <param name="output_path">输出路径</param>
/// <param name="text">写入文本</param>
/// <param name="scale">缩放比例</param>
public static void GetQRCode(String output_path, String text, Int32 scale)
{
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.L);
QrCode qrCode = new QrCode();
qrEncoder.TryEncode(text, out qrCode); Bitmap img = new Bitmap(qrCode.Matrix.Width * scale, qrCode.Matrix.Height * scale);
img.SetResolution(180f, 180f);
Graphics gdiobj = Graphics.FromImage(img);
gdiobj.CompositingQuality = CompositingQuality.HighQuality;
gdiobj.SmoothingMode = SmoothingMode.HighQuality;
gdiobj.InterpolationMode = InterpolationMode.HighQualityBicubic;
gdiobj.PixelOffsetMode = PixelOffsetMode.HighQuality; for (Int32 i = ; i < qrCode.Matrix.Height; i++)
{
for (Int32 j = ; j < qrCode.Matrix.Width; j++)
{
if (qrCode.Matrix.InternalArray[i, j])
{
gdiobj.FillRectangle(new SolidBrush(Color.Black), i * scale, j * scale, scale, scale);
}
}
} System.Drawing.Imaging.EncoderParameters ep = new System.Drawing.Imaging.EncoderParameters();
ep.Param[] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 800L); System.Drawing.Imaging.ImageCodecInfo ici = GetEncoder(ImageFormat.Png); if (ici != null)
{
img.Save(output_path, ici, ep);
}
else
{
img.Save(output_path, ImageFormat.Png);
}
img.Dispose();
gdiobj.Dispose();
}
比例的缩放没写好