/// <summary> /// 将图片转成字符串 /// </summary> /// <returns></returns> public JsonResultObject ImageBase64() { var result = new JsonResultObject(); HttpPostedFile imageFile = HttpContext.Current.Request.Files[0]; var fs = imageFile.InputStream; if (fs != null) { result.data = ImageConvertUtil.ConvertImageToBase64(fs); result.status = true; result.msg = "已完成数据转换!"; } else { result.status = false; } return(result); }
/// <summary> /// 上传图片 图片作byse64字符串流传递 /// </summary> public JsonResultObject UpLoadImage() { myLog.InfoFormat("开始"); var result = new JsonResultObject(); UpLoadImageInfo upLoadImageInfo = new UpLoadImageInfo(); upLoadImageInfo.ImageByte = HttpContext.Current.Request["imageByte"]; upLoadImageInfo.SourceType = HttpContext.Current.Request["sourceType"]; upLoadImageInfo.ExtName = HttpContext.Current.Request["extName"]; upLoadImageInfo.Type = HttpContext.Current.Request["type"]; upLoadImageInfo.FilePath = HttpContext.Current.Request["filePath"]; upLoadImageInfo.FileName = HttpContext.Current.Request["fileName"]; upLoadImageInfo.FilePath = upLoadImageInfo.FilePath == ""? null :upLoadImageInfo.FilePath; upLoadImageInfo.FileName = upLoadImageInfo.FileName == "" ? null : upLoadImageInfo.FileName; string index = HttpContext.Current.Request["index"]; if (index != null && index != "" && index != "0") { upLoadImageInfo.Index = int.Parse(index); } if (upLoadImageInfo.Type == null || upLoadImageInfo.Type == "") { upLoadImageInfo.Type = "other"; } if (string.IsNullOrEmpty(upLoadImageInfo.ImageByte) == false && upLoadImageInfo.ImageByte != "") { try { byte[] ibyte = ImageConvertUtil.FromBase64ToByte(upLoadImageInfo.ImageByte); result = ReturnUpLoadStatus(ibyte, upLoadImageInfo); //存放图片,并返回数据状态 } catch (Exception ex) { result.msg = "数据添加异常!"; myLog.InfoFormat("图片上传异常 " + ex.Message); } } else { result.status = false; result.msg = "上传失败,没有解析图片!"; } return(result); }