private void _btMetafile_Click(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Extended metafile (*.emf)|*.emf|Windows metafile (*.wmf)|*.wmf|All files (*.*)|*.*"; dlg.FilterIndex = 1; dlg.RestoreDirectory = true; if (dlg.ShowDialog() != DialogResult.OK) { return; } // create document C1WordDocument c1Word = new C1WordDocument(); c1Word.Info.Title = "Convert metafile to RTF example"; _statusBar.Text = "Creating document..."; Image img; string ext = Path.GetExtension(dlg.FileName); if (ext == ".wmf" || ext == ".emf") { img = Metafile.FromFile(dlg.FileName); } else { throw new FormatException("Not metafile."); } c1Word.DrawMetafile((Metafile)img); c1Word.PageBreak(); c1Word.AddPicture(img, RtfHorizontalAlignment.Left); c1Word.LineBreak(); Font font = new Font("Arial", 10, FontStyle.Regular); c1Word.AddParagraph(dlg.FileName, font, Color.Black); _statusBar.Text = "Saving document..."; string fileName = GetFileName(c1Word, "metafile.rtf"); c1Word.Save(fileName); Process.Start(fileName); _statusBar.Text = "Ready."; }
private void _tbPicture_Click(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Gif (*.gif)|*.gif|Png (*.png)|*.png|Jpeg (*.jpg)|*.jpg|Bitmap (*.bmp)|*.bmp|Windows metafile (*.wmf)|*.wmf|All files (*.*)|*.*"; dlg.FilterIndex = 6; dlg.RestoreDirectory = true; if (dlg.ShowDialog() != DialogResult.OK) { return; } // create document C1WordDocument c1Word = new C1WordDocument(); c1Word.Info.Title = "Show any picture sample"; _statusBar.Text = "Creating document..."; Font font = new Font("Arial", 14, FontStyle.Bold); c1Word.AddParagraph("Picture:", font, Color.Chocolate); Image img; string ext = Path.GetExtension(dlg.FileName); if (ext == ".wmf" || ext == ".emf") { img = Metafile.FromFile(dlg.FileName); } else { img = new Bitmap(dlg.FileName); } c1Word.AddPicture(img, RtfHorizontalAlignment.Left); c1Word.LineBreak(); font = new Font("Arial", 10, FontStyle.Regular); c1Word.AddParagraph(dlg.FileName, font, Color.Blue); _statusBar.Text = "Saving document..."; string fileName = GetFileName(c1Word, "picture.rtf"); c1Word.Save(fileName); Process.Start(fileName); _statusBar.Text = "Ready."; }
protected virtual void LoadImage() { try { string path = model.IconPath; if (path.EndsWith("WMF", StringComparison.OrdinalIgnoreCase)) { logger.Trace("WMF icon detected ({0})", path); Image = Metafile.FromFile(path); } else if (path.EndsWith("EMF", StringComparison.OrdinalIgnoreCase)) { logger.Trace("EMF icon detected ({0})", path); Image = Metafile.FromFile(path); } else if (path.EndsWith("SVG", StringComparison.OrdinalIgnoreCase)) { logger.Trace("SVG icon detected ({0})", path); SvgDocument svg = SvgDocument.Open(path); Image = svg.Draw(); } else { Image = Image.FromFile(path); } } catch (FileNotFoundException e) { string msg = String.Format("Icon couldn't be found! ({0})", model.IconPath); throw new ApplicationException(msg, e); } catch (OutOfMemoryException e) { string msg = String.Format("Icon doesn't have a valid image format! ({0})", model.IconPath); throw new ApplicationException(msg, e); } }
public void DrawFigure(Graphics g, IDictionary <string, object> props) { PointF location = new PointF((float)props["Left"], (float)props["Top"]); SizeF size = new SizeF((float)props["Width"], (float)props["Height"]); RectangleF rect = new RectangleF(location, size); string pathfile = (string)props["ImagePath"]; string filename = pathfile + (string)props["ImageName"]; if (File.Exists(filename)) { Image image; if (filename.ToUpper().EndsWith(".EMF")) { image = Metafile.FromFile(filename); } else { image = Bitmap.FromFile(filename); if ((bool)props["Transparent"]) { ((Bitmap)image).MakeTransparent(); } } if ((bool)props["Stretch"]) { g.DrawImage(image, rect); } else { if ((bool)props["Mozaika"]) { Size rsize = new Size(image.Width, image.Height); int rowcount = (int)Math.Ceiling(rect.Height / rsize.Height); int colcount = (int)Math.Ceiling(rect.Width / rsize.Width); for (int row = 0; row < rowcount; row++) { for (int col = 0; col < colcount; col++) { Point p = Point.Ceiling(rect.Location); p.Offset(col * rsize.Width, row * rsize.Height); Rectangle r = new Rectangle(p, new Size(rsize.Width, rsize.Height)); Rectangle master = Rectangle.Ceiling(rect); master.Intersect(r); g.DrawImageUnscaledAndClipped(image, master); } } } else { g.DrawImage(image, rect.Location); } } image.Dispose(); } else { using (Pen pen = new Pen(Color.Black)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; g.DrawRectangles(pen, new RectangleF[] { rect }); } } }
private void DumpMetas(string mask) { Cursor = Cursors.WaitCursor; _c1pdf.Clear(); _c1pdf.Compression = C1.C1Pdf.CompressionEnum.None; //_c1pdf.Compression = C1.C1Pdf.CompressionEnum.BestCompression; Random rnd = new Random(); Font font = new Font("Courier New", 9, FontStyle.Bold); // look for emf files in the executable directory string path = Path.GetDirectoryName(Application.ExecutablePath); bool first = true; string[] files = Directory.GetFiles(path, mask); foreach (string fileName in files) { statusBar1.Text = string.Format("Exporting {0}...", Path.GetFileName(fileName)); Application.DoEvents(); // new page if (!first) { _c1pdf.NewPage(); } first = false; // load metafile Metafile meta = (Metafile)Metafile.FromFile(fileName); // get metafile size in points SizeF szPage = GetImageSizeInPoints(meta); Console.WriteLine("Adding page {0:f2}\" x {1:f2}\"", szPage.Width / 72f, szPage.Height / 72f); // size page to metafile _c1pdf.PageSize = szPage; // draw metafile on the page RectangleF rc = _c1pdf.PageRectangle; _c1pdf.FillRectangle(Brushes.AntiqueWhite, rc); _c1pdf.DrawImage(meta, rc); _c1pdf.DrawString(fileName, font, Brushes.Black, rc); // draw thumbnail at random place rc.Width /= 5; rc.Height /= 5; rc.X = rnd.Next((int)(szPage.Width - rc.Width)); rc.Y = rnd.Next((int)(szPage.Height - rc.Height)); _c1pdf.FillRectangle(Brushes.White, rc); _c1pdf.DrawImage(meta, rc); _c1pdf.DrawRectangle(Pens.Black, rc); // add outline entry if there's more than one page if (files.Length > 1) { _c1pdf.AddBookmark(Path.GetFileName(fileName), 0, 0); } } // show the result statusBar1.Text = "Saving..."; SaveAndShow(@"c:\temp\test\metas.pdf"); Cursor = Cursors.Default; statusBar1.Text = "Ready"; }
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e) { string path = Path.GetDirectoryName(Application.ExecutablePath); pictureBox1.Image = Metafile.FromFile(path + "\\" + listBox1.SelectedItem.ToString()); }