BarcodeWriter writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Renderer = new BitmapRenderer
{
Foreground = Color.Black
},
Options = new ZXing.QrCode.QrCodeEncodingOptions
{
DisableECI = true,
Height = height,
Width = width,
Margin = 0,
CharacterSet = "UTF-8",
ErrorCorrection = ErrorCorrectionLevel.M
}
};
Bitmap bitmap = writer.Write(url);
if (!string.IsNullOrEmpty(userFace))
{
Bitmap bits = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(userFace);
if (bits != null)
{
//剪裁一个80*80的Logo图片
ImageCut img = new ImageCut(0, 0, 80, 80);
System.Drawing.Bitmap icon = img.KiCut(bits);
//userFace_b.jpg是一个边框的图片
Bitmap bits2 = new System.Drawing.Bitmap((System.Drawing.Bitmap)System.Drawing.Image.FromFile(Application.StartupPath + "/user/userFace_b.jpg"), 84, 84);
if (icon != null)
{
try
{
//画了2个边框,一个是logo,一个在logo周围加了一个边框
using (var graphics = System.Drawing.Graphics.FromImage(bitmap))
{
graphics.DrawImage(bits2, (bitmap.Width - bits2.Width) / 2, (bitmap.Height - bits2.Height) / 2);
graphics.DrawImage(icon, (bitmap.Width - icon.Width) / 2, (bitmap.Height - icon.Height) / 2);
}
}
catch (Exception ex)
{
}
finally
{
icon.Dispose();
GC.Collect();
}
}
bitmap.Save(fileName, ImageFormat.Jpeg);
}
}
return bitmap;
}
</div>
}
else if (h * Width / w < Height)