private void rotate_Click(object sender, EventArgs e) { ToolStripMenuItem tsmi = sender as ToolStripMenuItem; IContainerControl icc = tsmi.Owner.GetContainerControl(); PictureBox pb = tsmi.Owner.GetContainerControl() as PictureBox; pbInfo pbi = (pb.Parent as MyPictureBox).pbInfo; pbi.Rotate = float.Parse(tsmi.Text); Graphics g = Graphics.FromImage(pb.Image); g.RotateTransform(pbi.Rotate); pb.Refresh(); }
public MyPictureBox(Image img, pbInfo _pbInfo) { InitializeComponent(); pictureBox.Image = img; pbInfo = _pbInfo; label.Text = pbInfo.Server; pbInfo.pbInfoChanged += (a, b) => { switch (b.PropertyName) { case "FilePath": RefreshImage(pbInfo.FilePath); break; case "Rotation": comboBoxRotate.Text = pbInfo.Rotate.ToString(); break; case "Server": label.Text = pbInfo.Server; label.BackColor = System.Drawing.Color.Transparent; label.ForeColor = System.Drawing.Color.Black; break; case "Error": if (pbInfo.Error != null) { label.Text = pbInfo.Error.Message; label.BackColor = System.Drawing.Color.Red; label.ForeColor = System.Drawing.Color.White; } break; } }; comboBoxRotate.TextChanged += (a, b) => { PointF pf = new PointF(2, img.Height - 20); if (pbInfo.Rotate > 0) { img.RotateFlip(Stuff.getRotateFlipType(pbInfo.Rotate)); if (pbInfo.Rotate == 90 || pbInfo.Rotate == 270) { pictureBox.Size = new Size(240, 320); pf = new PointF(2, img.Height - 20); } } else { pictureBox.Size = new Size(320, 240); } }; }
public MyPictureBox(Image img,pbInfo _pbInfo) { InitializeComponent(); pictureBox.Image = img; pbInfo = _pbInfo; label.Text = pbInfo.Server; pbInfo.pbInfoChanged += (a, b) => { switch(b.PropertyName) { case "FilePath": RefreshImage(pbInfo.FilePath); break; case "Rotation": comboBoxRotate.Text = pbInfo.Rotate.ToString(); break; case "Server": label.Text = pbInfo.Server; label.BackColor = System.Drawing.Color.Transparent; label.ForeColor = System.Drawing.Color.Black; break; case "Error": if (pbInfo.Error != null) { label.Text = pbInfo.Error.Message; label.BackColor = System.Drawing.Color.Red; label.ForeColor = System.Drawing.Color.White; } break; } }; comboBoxRotate.TextChanged += (a, b) => { PointF pf = new PointF(2, img.Height - 20); if (pbInfo.Rotate > 0) { img.RotateFlip(Stuff.getRotateFlipType(pbInfo.Rotate)); if (pbInfo.Rotate == 90 || pbInfo.Rotate == 270) { pictureBox.Size = new Size(240, 320); pf = new PointF(2, img.Height - 20); } } else { pictureBox.Size = new Size(320, 240); } }; }
private void timer1_Tick(object sender, EventArgs e) { foreach (string str in allServers.Where(x => !blockedServers.Contains(x))) { WebClient wc = new WebClient(); try { DateTime dtnow = DateTime.Now; string strdirpath = Application.CommonAppDataPath + "\\" + str + "\\" + System.DateTime.Today.ToString("yyyyMMdd") + "\\"; if (!Directory.Exists(strdirpath)) { Directory.CreateDirectory(strdirpath); } string strpath = strdirpath + DateTime.Now.ToString("HHmmss") + strext; System.GC.Collect(); wc.DownloadFileCompleted += (x, y) => { dynamic d = y.UserState as dynamic; if (y.Error == null) { try { if (fireTorchToolStripMenuItem.Checked) { wc.DownloadString("http://" + d.Server + ":8080/disabletorch"); } } catch { } if (File.Exists(d.FilePath)) { try { Image img = Bitmap.FromFile(d.FilePath); float fontSize = getFontSize(img); Font font = new Font(DefaultFont.FontFamily, fontSize); MyPictureBox pb = getServerPictureBox(d.Server); bool bFound = (pb != null); if (bFound) { pbInfo pbi = pb.pbInfo; pbi.FilePath = d.FilePath; pbi.Server = d.Server; pbi.Error = null; PointF pf = new PointF(2, img.Height - (fontSize)); if (pbi.Rotate > 0) { img.RotateFlip(Stuff.getRotateFlipType(pbi.Rotate)); if (pbi.Rotate == 90 || pbi.Rotate == 270) { pb.Size = new Size(270, 320); pf = new PointF(2, img.Height - fontSize); } } else { pb.Size = new Size(320, 270); } if (writeTimestampToolStripMenuItem.Checked) { Graphics g = Graphics.FromImage(img); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawString(d.Now.ToString("yyyy-MM-dd HH:mm:ss"), font, new SolidBrush(Color.OrangeRed), pf); g.Save(); } pb.Image = img; pbi.FilePath = d.FilePath; pb.Refresh(); flowLayoutPanel1.Refresh(); } else { pb = new MyPictureBox(img, new pbInfo() { Server = d.Server, FilePath = d.FilePath }); pb.Size = new System.Drawing.Size(320, 270); pb.pbInfo.FilePath = d.FilePath; pb.pbInfo.Server = d.Server; pb.Cursor = Cursors.Hand; if (writeTimestampToolStripMenuItem.Checked) { Graphics g = Graphics.FromImage(img); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawString(d.Now.ToString("yyyy-MM-dd HH:mm:ss"), font, new SolidBrush(Color.OrangeRed), new PointF(2, img.Height - fontSize)); g.Save(); } pb.Image = img; pb.PictureBox.SizeMode = PictureBoxSizeMode.StretchImage; pb.PictureBox.ContextMenuStrip = createContextMenuStrip(pb); pb.Refresh(); flowLayoutPanel1.Controls.Add(pb); } if (saveFilesToolStripMenuItem.Checked) { if (writeTimestampToolStripMenuItem.Checked) { img.Save(d.FilePath.Replace(strext, "~" + strext), format); } } else { string dirpath = (new FileInfo(d.FilePath).DirectoryName); foreach (string fi in Directory.EnumerateFiles(dirpath, "*" + strext, SearchOption.TopDirectoryOnly)) { try { if (File.Exists(fi)) { File.Delete(fi); } } catch { } } } } catch (Exception ex) { } } } else { MyPictureBox pb = getServerPictureBox(d.Server); if (pb != null) { pb.pbInfo.Error = y.Error; } //flowLayoutPanel1.Controls.Remove(pb); } }; try { if (fireTorchToolStripMenuItem.Checked) { wc.DownloadString("http://" + str + ":8080/enabletorch"); } } catch { } wc.DownloadFileAsync(new Uri("http://" + str + ":8080/photo.jpg"), strpath, new { FilePath = strpath, Server = str, Now = dtnow }); } catch (Exception ex) { string s = ex.Message; } } }
private ContextMenuStrip createContextMenuStrip(MyPictureBox pb) { ContextMenuStrip contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); contextMenuStrip1.SuspendLayout(); ToolStripMenuItem serverToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ToolStripMenuItem torch = new System.Windows.Forms.ToolStripMenuItem(); ToolStripMenuItem focus = new System.Windows.Forms.ToolStripMenuItem(); ToolStripMenuItem rotateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ToolStripMenuItem rotate0 = new System.Windows.Forms.ToolStripMenuItem(); ToolStripMenuItem rotate90 = new System.Windows.Forms.ToolStripMenuItem(); ToolStripMenuItem rotate180 = new System.Windows.Forms.ToolStripMenuItem(); ToolStripMenuItem rotate270 = new System.Windows.Forms.ToolStripMenuItem(); contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { serverToolStripMenuItem, rotateToolStripMenuItem }); contextMenuStrip1.Size = new System.Drawing.Size(153, 48); // // rotateToolStripMenuItem // rotateToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { rotate0, rotate90, rotate180, rotate270 }); rotateToolStripMenuItem.Size = new System.Drawing.Size(152, 22); rotateToolStripMenuItem.Text = "Rotate"; torch.Size = new System.Drawing.Size(152, 22); torch.Text = "LED"; torch.CheckOnClick = true; torch.CheckedChanged += (s, d) => { try { WebClient wc = new WebClient(); wc.DownloadString("http://" + (s as ToolStripMenuItem).OwnerItem.Text + ":8080/" + (!torch.Checked ? "disable" : "enable") + "torch"); } catch { } }; focus.Size = new System.Drawing.Size(152, 22); focus.Text = "Focus"; focus.CheckOnClick = true; focus.CheckedChanged += (s, d) => { try { WebClient wc = new WebClient(); wc.DownloadString("http://" + (s as ToolStripMenuItem).OwnerItem.Text + ":8080/" + (!focus.Checked ? "no" : "") + "focus"); } catch { } }; serverToolStripMenuItem.Size = new System.Drawing.Size(152, 22); serverToolStripMenuItem.Text = pb.pbInfo.Server; //http://192.168.1.8:8080/enabletorch //http://192.168.1.8:8080/focus //http://192.168.1.8:8080/disabletorch //http://192.168.1.8:8080/enabletorch serverToolStripMenuItem.Click += (s, d) => { Process.Start("http://" + (s as ToolStripMenuItem).Text + ":8080"); }; serverToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { torch, focus }); // // rotate0 // rotate0.Size = new System.Drawing.Size(152, 22); rotate0.Text = "0"; rotate0.Click += (a, b) => { pbInfo pbi = pb.pbInfo; pb.Image.RotateFlip(Stuff.getRotateFlipType(360 - pbi.Rotate)); pbi.Rotate = 0; pb.Size = new Size(320, 240); pb.Refresh(); }; // // rotate90 // rotate90.Size = new System.Drawing.Size(152, 22); rotate90.Text = "90"; rotate90.Click += (a, b) => { pbInfo pbi = pb.pbInfo; pb.Image.RotateFlip(Stuff.getRotateFlipType(360 - pbi.Rotate)); pbi.Rotate = 90; pb.Size = new Size(240, 320); pb.Refresh(); }; // // rotate180 // rotate180.Size = new System.Drawing.Size(152, 22); rotate180.Text = "180"; rotate180.Click += (a, b) => { pbInfo pbi = pb.pbInfo; pb.Image.RotateFlip(Stuff.getRotateFlipType(360 - pbi.Rotate)); pbi.Rotate = 180; pb.Size = new Size(320, 240); pb.Refresh(); }; // // rotate270 // rotate270.Size = new System.Drawing.Size(152, 22); rotate270.Text = "270"; rotate270.Click += (a, b) => { pbInfo pbi = pb.pbInfo; pb.Image.RotateFlip(Stuff.getRotateFlipType(360 - pbi.Rotate)); pbi.Rotate = 270; pb.Size = new Size(240, 320); pb.Refresh(); }; contextMenuStrip1.ResumeLayout(); return(contextMenuStrip1); }