C# ASP.NET 手写板并生成图片保存
2021-02-05 14:14
阅读:414
YPE html>
标签:style ini user you reset 替换 form save 出现
前端:
@{ Layout = null; } "zh-CN">手写板签名demo "X-UA-Compatible" content="IE=edge,chrome=1" /> "UTF-8"> "description" content="overview & stats" /> "viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />"signature">"text-align: center"> "color: red">请按着鼠标写字签名。
"button" value="保存" id="yes" /> "button" value="下载" id="download" /> "button" value="重写" id="reset" />"someelement">"" id="images">
后台:
public ActionResult UploadSignature2(string src_data) { Class1.Base64StrToImage(src_data, "C:\\Users\\45448\\Desktop\\1\\"+ DateTime.Now.ToString("yyyyMMddHHss") + ".png"); return Json(1, JsonRequestBehavior.AllowGet); } ////// 将Base64字符串转换为图片并保存到本地 /// /// base64字符串 /// 图片保存地址,如:/Content/Images/10000.png /// public static bool Base64StrToImage(string base64Str, string savePath) { var ret = true; try { base64Str = base64Str.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "") .Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", ""); //将base64头部信息替换 var bitmap = Base64StrToImage(base64Str); if (bitmap != null) { //创建文件夹 var folderPath = savePath.Substring(0, savePath.LastIndexOf(‘\\‘)); ////FileHelper.CreateDir(folderPath); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } //图片后缀格式 var suffix = savePath.Substring(savePath.LastIndexOf(‘.‘) + 1, savePath.Length - savePath.LastIndexOf(‘.‘) - 1).ToLower(); var suffixName = suffix == "png" ? ImageFormat.Png : suffix == "jpg" || suffix == "jpeg" ? ImageFormat.Jpeg : suffix == "bmp" ? ImageFormat.Bmp : suffix == "gif" ? ImageFormat.Gif : ImageFormat.Jpeg; //这里复制一份对图像进行保存,否则会出现“GDI+ 中发生一般性错误”的错误提示 var bmpNew = new Bitmap(bitmap); bmpNew.Save(savePath, suffixName); bmpNew.Dispose(); bitmap.Dispose(); } else { ret = false; } } catch (Exception ex) { ret = false; } return ret; }
C# ASP.NET 手写板并生成图片保存
标签:style ini user you reset 替换 form save 出现
原文地址:https://www.cnblogs.com/zhang1f/p/11439969.html
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:C# ASP.NET 手写板并生成图片保存
文章链接:http://soscw.com/index.php/essay/51361.html
文章标题:C# ASP.NET 手写板并生成图片保存
文章链接:http://soscw.com/index.php/essay/51361.html
评论
亲,登录后才可以留言!