private void btnSave_Click(object sender, EventArgs e) { if (this.path == null) { this.path = Path.GetDirectoryName(Application.ExecutablePath); } if (this.tabControl1.SelectedTab == null) { return; } using (SaveFileDialog dg = new SaveFileDialog()) { dg.Filter = "Pliki PNG (*.png)|*.png|Pliki BMP (*.bmp)|*.bmp"; dg.FilterIndex = 0; dg.Title = "Zapisz obraz jako..."; dg.InitialDirectory = this.path; dg.FileName = this.tabControl1.SelectedTab.Text + ".png"; if (dg.ShowDialog() != DialogResult.OK) { return; } this.path = Path.GetDirectoryName(dg.FileName); ImageBrowser ib = this.tabControl1.SelectedTab.Controls[0] as ImageBrowser; Bitmap bmp = ib.GetImage(); switch (Path.GetExtension(dg.FileName).ToLower()) { case ".png": bmp.Save(dg.FileName, ImageFormat.Png); break; case ".jpeg": case ".jpg": bmp.Save(dg.FileName, ImageFormat.Jpeg); break; case ".bmp": bmp.Save(dg.FileName, ImageFormat.Bmp); break; case ".tiff": case ".tif": bmp.Save(dg.FileName, ImageFormat.Tiff); break; default: string f = Path.GetFileNameWithoutExtension(dg.FileName) + ".png"; bmp.Save(f, ImageFormat.Png); break; } } }
void DispatchBitmapInfo(BitmapInfo bi) { if (this.InvokeRequired) { this.Invoke(new BitmapInfoDelegate(DispatchBitmapInfo), bi); return; } TabPage p = null; string name = bi.name; if (String.IsNullOrEmpty(name)) { name = "Image"; } foreach (TabPage page in this.tabControl1.TabPages) { if (page.Text == bi.name) { p = page; break; } } ImageBrowser ib = null; if (p == null) { p = new TabPage(name); this.tabControl1.TabPages.Add(p); ib = new ImageBrowser(); p.Controls.Add(ib); ib.Dock = DockStyle.Fill; } else { ib = p.Controls[0] as ImageBrowser; } ib.SetImage(bi.image); ib.SetStatusText(string.Format("size={2}; min={0:N3}; max={1:N3}", bi.min, bi.max, bi.image.Size)); ib.Invalidate(); }
private void button2_Click(object sender, EventArgs e) { ImageBrowser.ZoomMode zm = ImageBrowser.ZoomMode.Fit; if ((int)button2.Tag == 1) { zm = ImageBrowser.ZoomMode.Normal; button2.Tag = 2; } else { zm = ImageBrowser.ZoomMode.Fit; button2.Tag = 1; } foreach (TabPage page in this.tabControl1.TabPages) { ImageBrowser ib = page.Controls[0] as ImageBrowser; ib.Zoom(zm); } this.Invalidate(); }