/// <summary> /// The following code will load the SVGDOM, render to a emf, and /// place the EMF on the clipboard. Kt seems more complicated than it should /// see http://www.dotnet247.com/247reference/msgs/23/118514.aspx /// for why the straight forward solution does not work. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void miCopy_Click( object sender, System.EventArgs e) { if (svgUrlCombo.Text.Length > 0) { int width = 500; int height = 500; // make SVG document with associated window so we can render it. SvgWindow window = new SvgWindow(width, height, null); GdiRenderer renderer = new GdiRenderer(); renderer.Window = window; window.Renderer = renderer; window.Src = svgUrlCombo.Text; // copy and paste code taken from // http://www.dotnet247.com/247reference/msgs/23/117611.aspx // putting a plain MetaFile on the clipboard does not work. // .Net's metafile format is not recognised by most programs. Graphics g = CreateGraphics(); IntPtr hdc = g.GetHdc(); Metafile m = new Metafile(hdc, EmfType.EmfOnly); g.ReleaseHdc(hdc); g.Dispose(); g = Graphics.FromImage(m); // draw the SVG here // NOTE: the graphics object is automatically Disposed by the // GdiRenderer. renderer.Graphics = g; renderer.Render(window.Document as SvgDocument); //window.Render(); // put meta file on the clipboard. IntPtr hwnd = this.Handle; if (Win32.OpenClipboard(hwnd)) { Win32.EmptyClipboard(); IntPtr hemf = m.GetHenhmetafile(); Win32.SetClipboardData(14, hemf); //CF_ENHMETAFILE=14 Win32.CloseClipboard(); } } }
private void button1_Click(object sender, EventArgs e) { checkBox1.Checked = false; foreach (var a in mSkeletonData.Animations) { skeletonAnimation.SetAnimation(0, a.Name, false); float interval = 1f / 30f; int frameNum = (int)(a.Duration / interval); int pos = 0; string dir = ".\\output\\" + a.Name; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } for (int i = 0; i < frameNum; i++) { string path = dir + "\\" + pos + ".png"; skeletonAnimation.Update(interval); skeletonAnimation.Apply(skeleton); pipeline.Begin(); Bitmap img = new Bitmap(panel1.Width, panel1.Height); Graphics g = Graphics.FromImage(img); if (skeleton != null) { skeletonAnimation.Apply(skeleton); GdiRenderer.Draw(skeleton, pipeline); } g.ResetTransform(); g.TranslateTransform(Center.X, Center.Y); g.ScaleTransform(Zoom, -Zoom); pipeline.End(g); g.ResetTransform(); g.Dispose(); Bitmap imgScaled = new Bitmap((int)(img.Width / 1.6), (int)(img.Height / 1.6)); Graphics g2 = Graphics.FromImage(imgScaled); g2.DrawImage(img, new Rectangle(0, 0, imgScaled.Width, imgScaled.Height)); g2.Dispose(); imgScaled.Save(path); pos++; } } }
private void FormMainConvertor_Load(object sender, EventArgs e) { Temp_Dir = Path.GetTempPath(); FFmpegConfig.FFmpegPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\ffmpeg.exe"; FFmpegConfig.UserInterfaceManager = new FFmpegUserInterfaceManager(this); worker = new BackgroundWorker(); worker.DoWork += Worker_DoWork; worker.WorkerReportsProgress = true; worker.ProgressChanged += Worker_ProgressChanged; worker.RunWorkerCompleted += Worker_RunWorkerCompleted; WindowsTaskbar = new Taskbar(this); AllowDrop = true; var renderer = new GdiRenderer(); imageDesignPanel1.SetRenderer(renderer); }
public IImageFile CreateImage() { this.SetupContainer(); this.Init(MainContainer, ChartContainer); this.BuildComponents(MainContainer, ChartContainer); var bitmap = new Bitmap(Size.Width, Size.Height); var renderer = new GdiRenderer(bitmap); using (var graphics = renderer.GetGraphics()) { this.DrawBeforeRender(graphics); renderer.Render(MainContainer); this.DrawAfterRender(graphics); if (AfterDraw != null) { AfterDraw(graphics); } } return(new ImageFile(bitmap)); }
private int singleRun(string filePath, bool saveLocal, bool saveImage) { DateTime startTime = DateTime.Now; GdiRenderer gdiRenderer = new GdiRenderer(); SvgWindow wnd = new SvgWindow(300, 300, gdiRenderer); SvgDocument doc = new SvgDocument(wnd); wnd.Document = doc; doc.Load(filePath); //wnd.Render(); if (((GdiRenderer)wnd.Renderer).RasterImage == null) { Console.WriteLine("ERROR: no image rendered"); } DateTime endTime = DateTime.Now; TimeSpan diff = endTime - startTime; if (saveLocal) { doc.Save(localPath); } if (saveImage) { ((GdiRenderer)wnd.Renderer).RasterImage.Save(imgPath, System.Drawing.Imaging.ImageFormat.Png); Console.WriteLine("Reference image saved as :\n" + imgPath); } wnd.Renderer = null; wnd = null; doc = null; return((int)diff.TotalMilliseconds); }
private void FormMainConvertor_Load(object sender, EventArgs e) { Ls_ProfileName.Items.Clear(); Ls_ProfileName.Items.AddRange(ListProfiles()); Temp_Dir = Path.GetTempPath(); LastDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos); FFmpegConfig.FFmpegPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\ffmpeg.exe"; FFmpegConfig.UserInterfaceManager = new FFmpegUserInterfaceManager(this); worker = new BackgroundWorker(); worker.DoWork += Worker_DoWork; worker.WorkerReportsProgress = true; worker.ProgressChanged += Worker_ProgressChanged; worker.RunWorkerCompleted += Worker_RunWorkerCompleted; WindowsTaskbar = new Taskbar(this); AllowDrop = true; var renderer = new GdiRenderer(); imageDesignPanel1.SetRenderer(renderer); }
/// <summary> /// Draws an <see cref="Identicon"/> in a specified GDI drawing context at position (0, 0). /// </summary> /// <param name="icon">The identicon to draw.</param> /// <param name="g">Drawing context in which the icon will be rendered.</param> public static void Draw(this Identicon icon, Graphics g) { var renderer = new GdiRenderer(g); icon.Draw(renderer); }
/// <summary> /// Draws an <see cref="Identicon"/> in a specified GDI drawing context. /// </summary> /// <param name="icon">The identicon to draw.</param> /// <param name="g">Drawing context in which the icon will be rendered.</param> /// <param name="rect">The bounds of the rendered icon, including padding.</param> public static void Draw(this Identicon icon, Graphics g, Rendering.Rectangle rect) { var renderer = new GdiRenderer(g); icon.Draw(renderer, rect); }
private void DrawRulers(Graphics g, Point rulerCenter, Rectangle rulerLimits, Rectangle highlightLimits, Rectangle selRect, Matrix mx) { g.SmoothingMode = SmoothingMode.None; //g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; Point zeroCamera = Point.Round(GdiRenderer.GetTransformedPoint(Point.Empty, mx, false)); //Rectangle maxRuler = new Rectangle(0, 0, 10000, 10000); Rectangle maxRuler = new Rectangle(Point.Empty, stage.CanvasSize); PointF[] pts = maxRuler.PointFs(); GdiRenderer.TransformPoints(pts, mx, false); PointF tl = pts[0]; PointF tr = pts[1]; PointF bl = pts[3]; double angleXRad = Math.Atan2(tr.Y - tl.Y, tr.X - tl.X); float angleX = (float)(angleXRad * 180f / Math.PI); double scaleX = (tr.X - tl.X) / (double)maxRuler.Width; double scaleY = (bl.Y - tl.Y) / (double)maxRuler.Height; GraphicsState gsOrg = g.Save(); //g.TranslateTransform(-mx.OffsetX, -mx.OffsetY, MatrixOrder.Append); g.RotateTransform(angleX, MatrixOrder.Append); g.TranslateTransform(rulerCenter.X, rulerCenter.Y, MatrixOrder.Append); if (boxId == RulerBoxId.Origin) { if (localMatrix != null) { localMatrix.Dispose(); } localMatrix = g.Transform.Clone(); } g.FillRectangle(rulerBrush, topLeftBox); g.DrawLines(darkPen, topLeftOutline); rects[(int)RulerBoxId.Origin + (int)boxId] = topLeftBox; DrawRulers(g, rulerLimits.Left, rulerLimits.Right, zeroCamera.X - rulerCenter.X, (float)scaleX, highlightLimits.X, highlightLimits.Width, selRect); g.TranslateTransform(-rulerCenter.X, -rulerCenter.Y, MatrixOrder.Append); g.RotateTransform(-90, MatrixOrder.Append); g.TranslateTransform(rulerCenter.X, rulerCenter.Y, MatrixOrder.Append); boxId += boxesPerRuler; DrawRulers(g, -rulerLimits.Bottom, -rulerLimits.Top, zeroCamera.Y - rulerCenter.Y, (float)scaleY, highlightLimits.Height, highlightLimits.Y, selRect); //stage.CurrentEditItem.guides.DrawHGuides(g); g.Restore(gsOrg); g.SmoothingMode = SmoothingMode.HighQuality; }
public void SetUp() { renderer = new GdiRenderer(); wnd = new SvgWindow(75, 75, renderer); doc = new SvgDocument(wnd); }