public ActionResult UploadImages() { try { HttpPostedFileBase hp = Request.Files["Filedata"]; //HttpPostedFile postedFile = context.Request.Files["Filedata"]; string tempPath = string.Empty; string originalpath = string.Empty; string publishedPath = string.Empty; string thumbnailsPath = string.Empty; //tempPath = "/" + System.Configuration.ConfigurationManager.AppSettings["FolderGalleryPath"] + "/{ReplaceThisPath}/" + date.Year + "/" + date.Month + "/"; tempPath = "/Uploads/Gallery/{ReplaceThisPath}/"; originalpath = HttpContext.Server.MapPath(tempPath.Replace("{ReplaceThisPath}", "Original")); publishedPath = HttpContext.Server.MapPath(tempPath.Replace("{ReplaceThisPath}", "Published")); thumbnailsPath = HttpContext.Server.MapPath(tempPath.Replace("{ReplaceThisPath}", "Thumbnails")); tempPath = tempPath.Replace("{ReplaceThisPath}", "Thumbnails"); //string filename = postedFile.FileName; string filename = hp.FileName; string sExtension = filename.Substring(filename.LastIndexOf('.')); string oldfilename = filename.Replace(sExtension, ""); if (!Directory.Exists(originalpath)) { Directory.CreateDirectory(originalpath); } if (!Directory.Exists(publishedPath)) { Directory.CreateDirectory(publishedPath); } if (!Directory.Exists(thumbnailsPath)) { Directory.CreateDirectory(thumbnailsPath); } string sNewFileName = DateTime.Now.ToString("yyyyMMddmmssfff"); //保存原图 hp.SaveAs(originalpath + @"/" + sNewFileName + sExtension); //postedFile.SaveAs(originalpath + @"/" + sNewFileName + sExtension); //保存加水印图 ImgProcess.MakeThumbnail(originalpath + @"/" + sNewFileName + sExtension, publishedPath + @"/" + sNewFileName + sExtension, 600, 450, null, null); //保存缩略图 ImgProcess.MakeThumbnail(originalpath + @"/" + sNewFileName + sExtension, thumbnailsPath + @"/" + sNewFileName + sExtension, 150, 100, null, null); //context.Response.Write(tempPath + sNewFileName + sExtension); //context.Response.StatusCode = 200; return(Content(tempPath + sNewFileName + sExtension, oldfilename)); } catch (Exception ex) { //context.Response.Write("错误: " + ex.Message); return(Content("错误: " + ex.Message)); } }
public ActionResult UploadImg() { //定义错误消息 string msg = ""; //接受上传文件 HttpPostedFileBase hp = Request.Files["upImage"]; if (hp != null) { //获取上传目录 转换为物理路径 string uploadPath = Server.MapPath("~/UpLoads/"); if (!Directory.Exists(uploadPath))//如果文件路径不存在,创建 { Directory.CreateDirectory(Server.MapPath("~/UpLoads/")); } //获取文件名 string fileName = DateTime.Now.Ticks.ToString() + System.IO.Path.GetExtension(hp.FileName); //获取文件大小 long contentLength = hp.ContentLength; //文件不能大于1M if (contentLength > 20 * 1024 * 1024) { msg = "文件大小超过限制要求."; return(Content("0")); } //保存文件的物理路径 string saveFile = uploadPath + fileName; string originalpath = Server.MapPath("~/UpLoads/s/"); if (!Directory.Exists(originalpath)) { Directory.CreateDirectory(originalpath); } string newFile = originalpath + fileName; //保存文件 hp.SaveAs(saveFile); ImgProcess.MakeThumbnail(saveFile, newFile, 600, 450, null, null); msg = "/UpLoads/s/" + fileName; } try { return(Content(msg)); //msg = "1"; } catch { msg = "上传失败."; return(Content(msg)); } }
private void ProcessWithCirclesFinder() { string bmpFile = ImgProcess.FormatBmp(TB_Filepath.Text); CirclesFinder f = new CirclesFinder((Bitmap)Bitmap.FromFile(bmpFile)); TB_OutputPath.Text = Utils.String.FilePostfix(TB_Filepath.Text, "-result").Replace(".jpg", ".bmp"); int width = PB_Result.Width; int height = PB_Result.Height; Bitmap b = f.Draw(TB_OutputPath.Text); b = new Bitmap(b, width, height); PB_Result.Image = b; ImgProcess.Count(f.Rounds); string txtFile = TB_OutputPath.Text.Replace(".bmp", ".txt"); using (System.IO.StreamWriter file = new System.IO.StreamWriter(txtFile, true)) { file.Write(string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8}", "ID", "X", "Y", "LengthOnX", "DeviationOnX", "LengthOnY", "DeviationOnY", "Weight", "DeviationOnWeight") + Environment.NewLine); foreach (var round in f.Rounds) { file.Write(string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8}", round.Id.ToString("D3"), round.CenterX, round.CenterY, round.MaxLenLine.Length, round.LenXDiff.ToString("F4"), round.EndY - round.StartY, round.LenYDiff.ToString("F4"), round.Weight.ToString(), round.WeightDiff.ToString("F4"))); file.Write(Environment.NewLine); } double radiusStdEv = Utils.Math.StdEv(f.Rounds.Select(x => (double)x.MaxLenLine.Length).ToList()); file.Write(string.Format("StdEv of Radius: {0}", radiusStdEv)); file.Write(Environment.NewLine); double weightStdEv = Utils.Math.StdEv(f.Rounds.Select(x => (double)x.Weight).ToList()); file.Write(string.Format("StdEv of Weight: {0}", weightStdEv)); file.Write(Environment.NewLine); } }
/* to be obsoleted */ private void ProcessWithCircleFinder() { //var rawData = mCamera.Execute(new Command("Read", new Dictionary<string, string> { { "Type", "Raw" } })).Param as Bitmap; string resultBmp = Utils.String.FilePostfix(_filePath, "-result"); string resultTxt = resultBmp.Replace(".bmp", ".txt"); Bitmap bmpFile = ImgProcess.Binarize(_filePath); CirclesFinder f = new CirclesFinder(bmpFile); LatestImage = f.Draw(resultBmp); ImgProcess.Count(f.Rounds); using (System.IO.StreamWriter file = new System.IO.StreamWriter(resultTxt, true)) { file.Write(string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8}", "ID", "X", "Y", "LengthOnX", "DeviationOnX", "LengthOnY", "DeviationOnY", "Weight", "DeviationOnWeight") + Environment.NewLine); foreach (var round in f.Rounds) { file.Write(string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8}", round.Id.ToString("D3"), round.CenterX, round.CenterY, round.MaxLenLine.Length, round.LenXDiff.ToString("F4"), round.EndY - round.StartY, round.LenYDiff.ToString("F4"), round.Weight.ToString(), round.WeightDiff.ToString("F4"))); file.Write(Environment.NewLine); } double radiusStdEv = Utils.Math.StdEv(f.Rounds.Select(x => (double)x.MaxLenLine.Length).ToList()); file.Write(string.Format("StdEv of Radius: {0}", radiusStdEv)); file.Write(Environment.NewLine); double weightStdEv = Utils.Math.StdEv(f.Rounds.Select(x => (double)x.Weight).ToList()); file.Write(string.Format("StdEv of Weight: {0}", weightStdEv)); file.Write(Environment.NewLine); } }
public void ProcessorTest_Binarize() { Bitmap i = (Bitmap)ImgProcess.Binarize(path + "Sample2-24b.bmp"); i.Save(path + "Sample2-24b-bin.bmp"); }