public static Bitmap Get(string path, int scaleRatio, Brush brush, SmoothingMode mode = SmoothingMode.HighQuality) { int svgPathSize = 8; int width = svgPathSize * scaleRatio + 1; int height = svgPathSize * scaleRatio + 1; List <Cmd> cmds; cmds = CmdParser.Parse(path); CmdValidator.ValidateCmds(cmds); cmds = CmdConverter.ExtractToSingleAndAbsolutePositionCmds(cmds); cmds = CmdScaler.Scale(cmds, scaleRatio); return(CmdDrawer.Draw(cmds, width, height, brush, mode)); }
private void DrawImage(List <Cmd> cmd) { InitBrushIfNeeded(); int scale = (int)nudScale.Value; int @base = (int)nudBase.Value; // process commands List <Cmd> processedCmds = cmd; processedCmds = CmdConverter.ExtractToSingleAndAbsolutePositionCmds(processedCmds); processedCmds = CmdScaler.Scale(processedCmds, scale); // display drawned into text box var cmdText = new StringBuilder(); processedCmds.ForEach(cm => cmdText.Append(cm.ToString())); txtParsedCmds.Text = cmdText.ToString(); // draw image into preview pbPreview.Image = CmdDrawer.Draw(processedCmds, @base * scale, @base * scale, br); }
private void Preview() { try { lblError.Text = string.Empty; // int scale = (int)nudScale.Value; _cmds = CmdParser.Parse(txtSVGPath.Text); List <Cmd> processedCmds = _cmds; processedCmds = CmdConverter.ExtractToSingleAndAbsolutePositionCmds(processedCmds); processedCmds = CmdScaler.Scale(processedCmds, scale); // load parse command into listview lbParsedCmds.SelectedIndexChanged -= lbParsedCmds_SelectedIndexChanged; lbParsedCmds.Items.Clear(); lbParsedCmds.Items.AddRange( _cmds .Select(i => i.ToString()) .ToArray()); lbParsedCmds.SelectedIndexChanged += lbParsedCmds_SelectedIndexChanged; // select last events lbParsedCmds.SelectedIndex = lbParsedCmds.Items.Count - 1; } catch (InvalidSvgCharacterException isce) { pbPreview.Image = null; lblError.Text = "Error: " + isce.Message; } catch (InvalidCmdException invalidCmdEx) { pbPreview.Image = null; lbParsedCmds.SelectedIndex = invalidCmdEx.Index; lblError.Text = "Error: " + invalidCmdEx.Message; } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }