public void SetDataSet(PhotoInformation photo, List <ZoneAxis> zoneaxis) { dataGridView2.Visible = false; label1.Text = zoneaxis.Count.ToString() + " candidates are found."; this.zoneAxis = zoneaxis; for (int i = 0; i < zoneaxis.Count; i++) { if (zoneaxis[i].plane1.IsRootIndex) { dataSet.Tables[0].Rows.Add(GetTabelRows(i, photo, zoneaxis[i])); } } if (photo.IsTriangleMode) { dataGridView1.Columns[5].Visible = true; dataGridView1.Columns[6].Visible = true; dataGridView1.Columns[7].Visible = false; } else { dataGridView1.Columns[5].Visible = false; dataGridView1.Columns[6].Visible = false; dataGridView1.Columns[7].Visible = true; } }
public List<PhotoInformation> GetPhotos(string sourceDirectory, bool copyImagesToOutputDirectory) { string[] temp = Directory.GetFiles(sourceDirectory, "*.jpg"); List<PhotoInformation> images = new List<PhotoInformation>(temp.Length); string previousPath = string.Empty; for(int index = 0; index < temp.Length; index++) { FileInfo info = new FileInfo(temp[index]); PhotoInformation photo = new PhotoInformation(); photo.Name = GetName(info); photo.Description = GetName(info); photo.PreviousImage = previousPath; photo.Path = GetPath(info, copyImagesToOutputDirectory); if((index + 1) < temp.Length) photo.NextImage = string.Format("{0}.html", GetName( new FileInfo(temp[index + 1]))); previousPath = string.Format("{0}.html", GetName(info)); images.Add(photo); } return images; }
public List <PhotoInformation> GetPhotos(string sourceDirectory, bool copyImagesToOutputDirectory) { string[] temp = Directory.GetFiles(sourceDirectory, "*.jpg"); List <PhotoInformation> images = new List <PhotoInformation>(temp.Length); string previousPath = string.Empty; for (int index = 0; index < temp.Length; index++) { FileInfo info = new FileInfo(temp[index]); PhotoInformation photo = new PhotoInformation(); photo.Name = GetName(info); photo.Description = GetName(info); photo.PreviousImage = previousPath; photo.Path = GetPath(info, copyImagesToOutputDirectory); if ((index + 1) < temp.Length) { photo.NextImage = string.Format("{0}.html", GetName(new FileInfo(temp[index + 1]))); } previousPath = string.Format("{0}.html", GetName(info)); images.Add(photo); } return(images); }
public FormTEMID() { InitializeComponent(); photo1 = new PhotoInformation(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0); photo2 = new PhotoInformation(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0); photo3 = new PhotoInformation(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0); }
public IActionResult Upload(PhotoInformation model) { var user = _httpContextAccessor.HttpContext.User; var userId = user.FindFirst(ClaimTypes.NameIdentifier).Value; var uploadTime = DateTime.Now.ToString("yyyy:MM:dd HH:mm:ss"); var season = Determineseason(model.PhotoTakeTime); if (ModelState.IsValid) { model.Id = userId; model.PhotoUploadTime = uploadTime; model.DeleteFlag = false; model.PhotoGrade = 100; model.PhotoSource = "网页端"; model.Season = season; try{ _context.PhotoInformation.Add(model); _context.SaveChanges(); ModelState.AddModelError("uploadResult", "上传成功"); }catch { ModelState.AddModelError("uploadResult", "上传失败,数据库连接错误"); } } else { ModelState.AddModelError("uploadResult", "上传失败,图片信息格式有误"); } return(View(model)); }
public object[] GetTabelRows(int i, PhotoInformation photo, ZoneAxis zoneaxis) => new object[] { i, "[" + zoneaxis.u.ToString() + " " + zoneaxis.v.ToString() + " " + zoneaxis.w.ToString() + "]", zoneaxis.plane1.h.ToString() + " " + zoneaxis.plane1.k.ToString() + " " + zoneaxis.plane1.l.ToString(), zoneaxis.plane1.d.ToString("f3") + "nm (" + ((zoneaxis.plane1.d - photo.d1) / photo.d1 * 100).ToString("f3") + "%)", zoneaxis.plane2.h.ToString() + " " + zoneaxis.plane2.k.ToString() + " " + zoneaxis.plane2.l.ToString(), zoneaxis.plane2.d.ToString("f3") + "nm (" + ((zoneaxis.plane2.d - photo.d2) / photo.d2 * 100).ToString("f3") + "%)", zoneaxis.plane3.h.ToString() + " " + zoneaxis.plane3.k.ToString() + " " + zoneaxis.plane3.l.ToString(), zoneaxis.plane3.d.ToString("f3") + "nm (" + ((zoneaxis.plane3.d - photo.d3) / photo.d3 * 100).ToString("f3") + "%)", (zoneaxis.Theta / Math.PI * 180).ToString("f3") + "�� (" + ((zoneaxis.Theta - photo.Theta) / Math.PI * 180).ToString("f3") + "��)", zoneaxis.Phase };
public async Task <IActionResult> Post(string LoginEmail, int source) { if (LoginEmail.Length > 0) { ApplicationUser signinUser = await _userManager.FindByEmailAsync(LoginEmail); string userId = signinUser.Id; var uploadFile = Request.Form.Files; if (uploadFile.Count > 0) { string filePath = _environment.ContentRootPath + "/wwwroot/user/" + userId; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } foreach (var file in uploadFile) { var filename = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); string imagePath = filePath + "/" + filename; using (FileStream fs = System.IO.File.Create(imagePath)) { await file.CopyToAsync(fs); fs.Flush(); } string extension = filename.Split('.')[1]; if (!pictureFormatArray.Contains(extension)) { //数据文件 string xmlPath = "../../user/" + userId + "/" + filename; string imagePathInDataBase = "../../user/" + userId + "/" + filename.Split('.')[0] + ".JPG"; XDocument xmlDoc = XDocument.Load(imagePath); PList plist = new PList(); plist.Load(imagePath); var altitude = plist.GetValue("altitude"); var longitutde = plist.GetValue("longitude"); var latitude = plist.GetValue("latitude"); var plantName = plist.GetValue("name"); var phenomenon = plist.GetValue("phenomenon"); var time = plist.GetValue("time"); var weather = plist.GetValue("weather"); var wind = plist.GetValue("wind"); var date = plist.GetValue("normalDate"); var chineseDate = plist.GetValue("chineseDate"); if (altitude.ToString() == "未获取") { altitude = "0"; } if (latitude.ToString() == "未获取") { latitude = "0"; } if (longitutde.ToString() == "未获取") { longitutde = "0"; } if (weather.ToString() == "未获取天气") { } else { var weatherArray = weather.ToString().Split('℃'); string temperature = weatherArray[0] + "℃" + weatherArray[1] + "℃"; weather = weatherArray[2]; } if (wind.ToString() == "未获取风速") { wind = null; } //var user = _httpContextAccessor.HttpContext.User; //var userId = user.FindFirst(ClaimTypes.NameIdentifier).Value; var uploadTime = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"); //var season = Determineseason(model.PhotoTakeTime); PhotoInformation model = new PhotoInformation(); model.Id = userId; model.PhotoUploadTime = uploadTime; model.DeleteFlag = false; model.PhotoGrade = 100; model.AlbumName = "默认相册"; if (source == 1) { model.PhotoSource = "iOS客户端"; } else if (source == 2) { model.PhotoSource = "Android客户端"; } model.PhotoTakeTime = date.ToString() + " " + time.ToString(); model.PhotoLatitude = Convert.ToDecimal(latitude.ToString()); model.PhotoLongitude = Convert.ToDecimal(longitutde.ToString()); model.PhotoHeight = Convert.ToSingle(altitude.ToString()); model.PhotoPhenology = phenomenon.ToString(); model.Weather = weather.ToString(); model.LunarTime = chineseDate.ToString(); model.PhotoLink = imagePathInDataBase; model.PhotoPlant = plantName.ToString(); //model.Temperature = temperature; //model.Season = season; _context.PhotoInformation.Add(model); _context.SaveChanges(); } else { _photoUrl = imagePath; } } string message = $"{uploadFile.Count} file(s) uploaded successfully!"; return(Json(message)); } return(Json($"{uploadFile.Count} failed uplaod")); } else { return(Json("no account active")); } }
// private bool IsTextChangedEventSkiped = false; private void textBox_TextChanged(object sender, EventArgs e) { //if (IsTextChangedEventSkiped) return; //IsTextChangedEventSkiped = true; double waveLength = 1.2264262862108010441350327657997 / Math.Sqrt((double)numericUpDownAccVol.Value * 1000 * (1 + (double)numericUpDownAccVol.Value * 0.9784753725226711491437618236159 / 1000)); double cameraLength = (double)numericUpDownCamaraLength.Value; inputBoxP1L1.CameraLength = inputBoxP1L2.CameraLength = inputBoxP1L3.CameraLength = inputBoxP2L1.CameraLength = inputBoxP2L2.CameraLength = inputBoxP2L3.CameraLength = inputBoxP3L1.CameraLength = inputBoxP3L2.CameraLength = inputBoxP3L3.CameraLength = cameraLength; inputBoxP1L1.WaveLength = inputBoxP1L2.WaveLength = inputBoxP1L3.WaveLength = inputBoxP2L1.WaveLength = inputBoxP2L2.WaveLength = inputBoxP2L3.WaveLength = inputBoxP3L1.WaveLength = inputBoxP3L2.WaveLength = inputBoxP3L3.WaveLength = waveLength; checkBoxEquivalentPhoto1L1Photo2L1_CheckedChanged(new object(), new EventArgs()); photo1 = new PhotoInformation(inputBoxP1L1.Length, inputBoxP1L2.Length, inputBoxP1L3.Length, numericBoxP1Theta.RadianValue, (double)numericUpDownPhoto1L1Err.Value / 100, (double)numericUpDownPhoto1L2Err.Value / 100, (double)numericUpDownPhoto1L3Err.Value / 100, (double)numericUpDownPhoto1ThetaErr.Value / 180 * Math.PI, numericBoxP1Tilt1.RadianValue, numericBoxP1Tilt2.RadianValue, (double)numericUpDownPhoto1Tilt1Err.Value / 180 * Math.PI, (double)numericUpDownPhoto1Tilt2Err.Value / 180 * Math.PI, radioButtonPhoto1Mode1.Checked, waveLength, cameraLength); if (photo1.IsTriangleMode) { numericBoxP1Theta.RadianValue = photo1.Paintable ? photo1.Theta : 0; } else { inputBoxP1L3.Length = photo1.Paintable ? photo1.L3 : 0; } photo2 = new PhotoInformation(inputBoxP2L1.Length, inputBoxP2L2.Length, inputBoxP2L3.Length, numericBoxP2Theta.RadianValue, (double)numericUpDownPhoto2L1Err.Value / 100, (double)numericUpDownPhoto2L2Err.Value / 100, (double)numericUpDownPhoto2L3Err.Value / 100, (double)numericUpDownPhoto2ThetaErr.Value / 180 * Math.PI, numericBoxP2Tilt1.RadianValue, numericBoxP2Tilt2.RadianValue, (double)(numericUpDownPhoto2Tilt1Err.Value) / 180 * Math.PI, (double)(numericUpDownPhoto2Tilt2Err.Value) / 180 * Math.PI, radioButtonPhoto2Mode1.Checked, waveLength, cameraLength); if (photo2.IsTriangleMode) { numericBoxP2Theta.RadianValue = photo2.Paintable ? photo2.Theta : 0; } else { inputBoxP2L3.Length = photo2.Paintable ? photo2.L3 : 0; } photo3 = new PhotoInformation(inputBoxP3L1.Length, inputBoxP3L2.Length, inputBoxP2L3.Length, numericBoxP3Theta.RadianValue, (double)numericUpDownPhoto3L1Err.Value / 100, (double)numericUpDownPhoto3L2Err.Value / 100, (double)numericUpDownPhoto3L3Err.Value / 100, (double)numericUpDownPhoto3ThetaErr.Value / 180 * Math.PI, numericBoxP3Tilt1.RadianValue, numericBoxP3Tilt2.RadianValue, (double)(numericUpDownPhoto3Tilt1Err.Value) / 180 * Math.PI, (double)(numericUpDownPhoto3Tilt2Err.Value) / 180 * Math.PI, radioButtonPhoto3Mode1.Checked, waveLength, cameraLength); if (photo3.IsTriangleMode) { numericBoxP3Theta.RadianValue = photo3.Paintable ? photo3.Theta : 0; } else { inputBoxP3L3.Length = photo3.Paintable ? photo3.L3 : 0; } buttonSearchPhoto1.Enabled = photo1.Paintable; buttonSearchPhoto2.Enabled = photo2.Paintable; buttonSearchPhoto3.Enabled = photo3.Paintable; //二つ以上がPanitableなときAllボタンをEnableにする buttonSearchAll.Enabled = (photo1.Paintable && photo2.Paintable && checkBoxPhoto2.Checked) || (photo1.Paintable && photo2.Paintable && checkBoxPhoto2.Checked && checkBoxPhoto3.Checked && photo3.Paintable); if (photo1.Paintable && photo2.Paintable && checkBoxPhoto3.Checked && photo3.Paintable) { buttonSearchAll.Text = "Search zone axes from three patterns"; } else { buttonSearchAll.Text = "Search zone axes from two patterns"; } //最大の長さを調べて、その値で50を割ったときの値がmagになる double maxlength = double.NegativeInfinity; if (photo1.Paintable) { maxlength = Math.Max(photo1.L1, photo1.L2); } if (photo2.Paintable) { maxlength = Math.Max(maxlength, Math.Max(photo2.L1, photo2.L2)); } if (photo3.Paintable) { maxlength = Math.Max(maxlength, Math.Max(photo3.L1, photo3.L2)); } double mag; if (maxlength > 0) { mag = 40 / maxlength; } else { mag = 50; } pictureBoxPhoto1.Image = DrawPic(photo1, pictureBoxPhoto1.Size, mag); double rot = 0;//回転を決める if (checkBoxEquivalentPhoto1L2Photo2L2.Checked) { rot = Math.Atan2(photo2.P2.Y, photo2.P2.X) - Math.Atan2(photo1.P2.Y, photo1.P2.X); } photo2.Rot(rot); pictureBoxPhoto2.Image = DrawPic(photo2, pictureBoxPhoto2.Size, mag); if (checkBoxEquivalentPhoto2L1Photo3L1.Checked) { rot = Math.Atan2(photo2.P1.Y, photo2.P1.X) - Math.Atan2(photo3.P1.Y, photo3.P1.X); } else if (checkBoxEquivalentPhoto2L2Photo3L2.Checked) { rot = Math.Atan2(photo2.P2.Y, photo2.P2.X) - Math.Atan2(photo3.P2.Y, photo3.P2.X); } else { rot = 0; } photo3.Rot(rot); pictureBoxPhoto3.Image = DrawPic(photo3, pictureBoxPhoto3.Size, mag); //IsTextChangedEventSkiped = false; }
private Bitmap DrawPic(PhotoInformation photo, Size size, double mag) { Bitmap bmp = new Bitmap(size.Width, size.Height); Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if (photo.Paintable) { g.Clear(Color.White); } else { g.Clear(Color.LightGray); } PointF p1, p2; if (photo.Paintable)//ベクトルの位置を決める { p1 = new PointF((float)(mag * photo.P1.X), (float)(mag * photo.P1.Y)); p2 = new PointF((float)(mag * photo.P2.X), (float)(mag * photo.P2.Y)); } else { p1 = new PointF(50, 0); p2 = new PointF(10, -70); } PointF offset = new PointF(-(p1.X + p2.X) / 3f + bmp.Width / 2f, -(p1.Y + p2.Y) / 3f + bmp.Height / 2f); //補助線を書く Pen penArc = new Pen(Brushes.Gray, 1 / 10f); Pen penLine = new Pen(Brushes.Gray, 1 / 10f); string str; //p1 double angle = Math.Atan2(p1.Y, p1.X); float length = (float)Math.Sqrt(p1.X * p1.X + p1.Y * p1.Y); g.Transform = new System.Drawing.Drawing2D.Matrix((float)Math.Cos(angle), (float)Math.Sin(angle), -(float)Math.Sin(angle), (float)Math.Cos(angle), offset.X, offset.Y); g.DrawArc(penArc, new RectangleF(0, -length / 4, length, length / 2), 0, 180); g.DrawLine(penLine, 0, 0, length, 0); //p2 angle = Math.Atan2(p2.Y, p2.X); length = (float)Math.Sqrt(p2.X * p2.X + p2.Y * p2.Y); g.Transform = new System.Drawing.Drawing2D.Matrix((float)Math.Cos(angle), (float)Math.Sin(angle), -(float)Math.Sin(angle), (float)Math.Cos(angle), offset.X, offset.Y); g.DrawArc(penArc, new RectangleF(0, -length / 4, length, length / 2), 180, 180); g.DrawLine(penLine, 0, 0, length, 0); //p3 if (photo.IsTriangleMode) { PointF p3 = new PointF(p2.X - p1.X, p2.Y - p1.Y); angle = Math.Atan2(p3.Y, p3.X); length = (float)Math.Sqrt(p3.X * p3.X + p3.Y * p3.Y); g.Transform = new System.Drawing.Drawing2D.Matrix((float)Math.Cos(angle), (float)Math.Sin(angle), -(float)Math.Sin(angle), (float)Math.Cos(angle), p1.X + offset.X, p1.Y + offset.Y); g.DrawArc(penArc, new RectangleF(0, -length / 4, length, length / 2), 0, 180); g.DrawLine(penLine, 0, 0, length, 0); } else //theta { g.Transform = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, offset.X, offset.Y); float r = (float)(Math.Min(Math.Sqrt(p1.X * p1.X + p1.Y * p1.Y), Math.Sqrt(p2.X * p2.X + p2.Y * p2.Y)) / 2); g.DrawArc(penArc, new RectangleF(-r / 2, -r / 2, r, r), (float)(Math.Atan2(p1.Y, p1.X) / Math.PI * 180), (float)((Math.Atan2(p2.Y, p2.X) - Math.Atan2(p1.Y, p1.X)) / Math.PI * 180)); } //次に点を描く g.Transform = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, offset.X, offset.Y); float ptSize = 8; for (int n = 1; n < double.PositiveInfinity; n++) { bool flag = true; for (int i = -n; i <= n; i++) { for (int j = Math.Abs(i) - n; j <= -Math.Abs(i) + n; j += -Math.Abs(i) + n != 0 ? 2 * (-Math.Abs(i) + n) : 1) { PointF p = new PointF(p1.X * i + p2.X * j, p1.Y * i + p2.Y * j); if (g.IsVisible(p)) { g.FillEllipse(new SolidBrush(Color.Black), p.X - ptSize / 2, p.Y - ptSize / 2, ptSize, ptSize); flag = false; } } } if (flag) { g.FillEllipse(new SolidBrush(Color.Red), -ptSize / 2, -ptSize / 2, ptSize, ptSize); break; } } //最後に字を書く Font strFont = new Font("tahoma", 7.5f, FontStyle.Regular); SolidBrush brush = new SolidBrush(Color.SlateBlue); g.Transform = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0); if (!photo.Paintable) { if (photo.IsTriangleMode) { g.DrawString("Input values of l1, l2, & l3", strFont, brush, 0, 0); } else { g.DrawString("Input values of l1, l2, & θ", strFont, brush, 0, 0); } } g.Transform = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, offset.X, offset.Y); //p1 str = photo.Paintable ? "L1 = " + photo.L1.ToString() + "mm" : "L1"; g.DrawString(str, strFont, brush, p1.X / 2f - p1.Y / 4f, p1.Y / 2f + p1.X / 4f); //p2 str = photo.Paintable ? "L2 = " + photo.L2.ToString() + "mm" : "L2"; if (photo.Paintable) { g.DrawString(str, strFont, brush, p2.X / 2f + p2.Y / 4f - 50, p2.Y / 2f - p2.X / 4f); } else { g.DrawString(str, strFont, brush, p2.X / 2f + p2.Y / 4f - 15, p2.Y / 2f - p2.X / 4f); } //p3 if (photo.IsTriangleMode) { str = photo.Paintable ? "L3 = " + photo.L3.ToString() + "mm" : "L3"; g.DrawString(str, strFont, brush, (p2.X + p1.X) / 2f - (p2.Y - p1.Y) / 4f + 5, (p1.Y + p2.Y) / 2f + (p2.X - p1.X) / 4f); } else //theta { float r = (float)(Math.Min(Math.Sqrt(p1.X * p1.X + p1.Y * p1.Y), Math.Sqrt(p2.X * p2.X + p2.Y * p2.Y)) / 2); angle = (Math.Atan2(p2.Y, p2.X) + Math.Atan2(p1.Y, p1.X)) / 2; str = photo.Paintable ? "θ = " + (photo.Theta / Math.PI * 180).ToString("f2") + "°" : "θ"; g.DrawString(str, strFont, brush, (float)(r * Math.Cos(angle) / 2) + 5, (float)(r * Math.Sin(angle) / 2) - 10); } return(bmp); }