diff --git a/App_Code/CommonUse.cs b/App_Code/CommonUse.cs index 418324e..2a53ffb 100644 --- a/App_Code/CommonUse.cs +++ b/App_Code/CommonUse.cs @@ -1499,7 +1499,6 @@ public class CommonUse break; } } - return bitmap; } diff --git a/Temp/Default.aspx.cs b/Temp/Default.aspx.cs index 4c6ef10..4590f58 100644 --- a/Temp/Default.aspx.cs +++ b/Temp/Default.aspx.cs @@ -314,9 +314,8 @@ public partial class 外部答题卡_Default : System.Web.UI.Page Response.Write("NO DATA"); return false; } - Bitmap PictureBoxBitMap = ImgGet(dt.Rows[0]["TempPicture64_nvarchar"].ToString()); + Bitmap PictureBoxBitMap = UrlToImage(dt.Rows[0]["TempPicture64_nvarchar"].ToString()); - //var PictureBoxBitMap = commonUse.RotateByOrientation(tempPictureBoxBitMap); if (PictureBoxBitMap == null) { Response.Write("NO PICTURE"); @@ -337,7 +336,7 @@ public partial class 外部答题卡_Default : System.Web.UI.Page Image myImage = new Image(PictureBoxBitMap); // 进行中值滤波 - CvInvoke.MedianBlur(myImage, myImage, 13); + CvInvoke.MedianBlur(myImage, myImage, 11); // 进行高斯滤波 CvInvoke.GaussianBlur(myImage, myImage, new Size(0, 0), 3); @@ -352,7 +351,7 @@ public partial class 外部答题卡_Default : System.Web.UI.Page VectorOfVectorOfPoint selected_contours1 = commonUse.GetUsefulContoursDingWei(mat_dilate, 1); //var color_mat1 = commonUse.DrawContours(mat_dilate, selected_contours1); - //commonUse.ShowMatWaitKey("44444", color_mat1, 0.6); + //commonUse.ShowMatWaitKey("44444", color_mat1, 0.8); //Response.Write(ImgToBase64String(color_mat1.Bitmap)); //return false; @@ -1098,6 +1097,43 @@ public partial class 外部答题卡_Default : System.Web.UI.Page } } + public static Bitmap UrlToImage(string url) + { + WebRequest imgRequest = WebRequest.Create(url); + + HttpWebResponse res = null; + try + { + res = (HttpWebResponse)imgRequest.GetResponse(); + imgRequest.Timeout = 50000; + if (res.StatusCode.ToString() == "OK") + { + var tempbitmap = new Bitmap(imgRequest.GetResponse().GetResponseStream()); + + // 别删!图片和网页中的方向不一致,根据图片中的方向信息,旋转图片后识别 + return new CommonUse().RotateByOrientation(tempbitmap); + } + else + { + return null; + } + } + catch (WebException ex) + { + res = (HttpWebResponse)ex.Response; + return null; + } + finally + { + if (res != null) + { + res.Dispose(); + res.Close(); + } + imgRequest.Abort(); + } + } + } diff --git a/Temp/TempDraw.aspx.cs b/Temp/TempDraw.aspx.cs index fc7859b..08174df 100644 --- a/Temp/TempDraw.aspx.cs +++ b/Temp/TempDraw.aspx.cs @@ -287,7 +287,8 @@ public partial class Temp_TempDraw : System.Web.UI.Page imgRequest.Timeout = 50000; if (res.StatusCode.ToString() == "OK") { - return new Bitmap(imgRequest.GetResponse().GetResponseStream()); + var tempbitmap = new Bitmap(imgRequest.GetResponse().GetResponseStream()); + return new CommonUse().RotateByOrientation(tempbitmap); } else { diff --git a/Temp/UserTemp.aspx.cs b/Temp/UserTemp.aspx.cs index bc6c6df..19615d4 100644 --- a/Temp/UserTemp.aspx.cs +++ b/Temp/UserTemp.aspx.cs @@ -149,7 +149,8 @@ public partial class Temp_UserTemp : System.Web.UI.Page Response.Write("NODATA"); return; } - Bitmap PictureBoxBitMap = ImgGet(dt.Rows[0]["TempPicture64_nvarchar"].ToString()); + Bitmap temp = ImgGet(dt.Rows[0]["TempPicture64_nvarchar"].ToString()); + var PictureBoxBitMap = new CommonUse().RotateByOrientation(temp); if (PictureBoxBitMap == null) { Response.Write("NOPICTURE");