c# API接收Base64转图片

/// <summary>
/// API接收Base64转图片
/// </summary>
/// <param name="Img">图片字节</param>
/// <param name="Path">储存地址</param>
/// <returns></returns>
public IHttpActionResult Index(String Img, String Path)
{
//转图片
byte[] bit = Convert.FromBase64String(Img);
MemoryStream ms = new MemoryStream(bit);
Bitmap bmp = new Bitmap(ms);
bmp.Save(HttpContext.Current.Server.MapPath(Path) + ".jpg", ImageFormat.Jpeg);
return Ok();
}
        /// <summary>
        /// API接收路径图片转Base64
        /// </summary>
        /// <param name="ImagePath">图片地址</param>
        /// <returns></returns>
        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 = ;
            ms.Read(arr, , (int)ms.Length);
            ms.Close();
            return Ok(arr);
        }
上一篇:通过data:image/png;base64把图片直接写在src里


下一篇:editplus 替换换行 excel 表格 拼装sql语句技巧