2022.5.1今天加班
Base64->图片
byte[] bit = Convert.FromBase64String(ret.data.oauthMPCode); using (MemoryStream ms = new MemoryStream(bit)) { Bitmap bmp = new Bitmap(ms); string filepath = AppDomain.CurrentDomain.BaseDirectory + "\\QrCode\\" + DateTime.Now.ToString("yyyyMMdd")+"\\"; if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } bmp.Save(filepath + ret.data.transactionId+".png", ImageFormat.Png); }
Base64->pdf
byte[] bit = Convert.FromBase64String(ret.data); string filepath = AppDomain.CurrentDomain.BaseDirectory + "\\QrPdf\\" + DateTime.Now.ToString("yyyyMMdd") + "\\"; if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } FileStream stream = new FileStream(filepath + dIn.fileCode + ".pdf", FileMode.CreateNew); BinaryWriter writer = new BinaryWriter(stream); writer.Write(bit, 0, bit.Length); writer.Close();
图片->Base64
public IHttpActionResult Index(String ImagePath) { Bitmap bmp = new Bitmap(HttpContext.Current.Server.MapPath(ImagePath)); MemoryStream ms = new MemoryStream(); bmp.Save(ms, ImageFormat.Jpeg); byte[] arr = new byte[ms.Length]; ms.Position = 0; ms.Read(arr, 0, (int)ms.Length); ms.Close(); return Ok(arr); }