// <summary>
/// 获取链接地址对应的二维码图像
/// /// </summary>
public static Bitmap ToQR(String str)
{
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M);
QrCode qrCode = qrEncoder.Encode(str);
GraphicsRenderer render = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Two), Brushes.Black, Brushes.White);
DrawingSize size = render.SizeCalculator.GetSize(qrCode.Matrix.Width);
Bitmap pic = new Bitmap(size.CodeWidth, size.CodeWidth);
Graphics g = Graphics.FromImage(pic);
render.Draw(g, qrCode.Matrix);
return pic;
}
/// <summary>
/// 保存图像
/// </summary>
public void Save(Bitmap pic, String filePath)
{
if (System.IO.File.Exists(filePath))
System.IO.File.Delete(filePath);
pic.Save(Server.MapPath(filePath), ImageFormat.Png);
}
public byte[] SaveImage(String path)
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); //将图片以文件流的形式进行保存
BinaryReader br = new BinaryReader(fs);
byte[] imgBytesIn = br.ReadBytes((int)fs.Length); //将流读入到字节数组中
return imgBytesIn;
}
public byte[] BitmapToBype(Bitmap b)
{
MemoryStream ms = new MemoryStream();
b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] bytes = ms.GetBuffer(); //byte[] bytes= ms.ToArray(); 这两句都可以,至于区别么,下面有解释
ms.Close();
return bytes;
}