/// <summary> /// Action responsible to replace the color of the original image. /// </summary> /// <param name="sender">The source calling the event.</param> /// <param name="e">The arguments passed to the event.</param> private void btnReplaceColor_Click(object sender, EventArgs e) { if (!ValidateFormControls()) { return; } foreach (Svg.SvgElement item in svgDocument.Children) { ChangeFill(item, btnSourceColor.BackColor, btnDestinationColor.BackColor); } pictConvertedImage.Image = svgDocument.Draw(); }
public static void Generate(DegradomeType dType, int length, int index) { string dotBracket = GetStruct(dType, length, index); string outputFile = RnaPlotWrapper.Plot(dotBracket); File.Copy(outputFile, $"{Config.WorkingFolder}\\cs_rna_struct\\plot\\{dType}_{length}_{index}.svg"); Svg.SvgDocument doc = SvgDocument.Open(outputFile); doc.Draw().Save($"{Config.WorkingFolder}\\cs_rna_struct\\plot\\{dType}_{length}_{index}.png"); }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { var ret = base.OnExposeEvent(evnt); using (Graphics g = Gtk.DotNet.Graphics.FromDrawable(evnt.Window)) { SvgOrigin.Draw(g); } return(ret); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string tSvg = Request["svg"]; string fileName = Request["unitId"]; MemoryStream tData = new MemoryStream(Encoding.UTF8.GetBytes(tSvg)); Svg.SvgDocument tSvgObj = SvgDocument.Open(tData); tSvgObj.Draw().Save("e:\\" + fileName + ".png", ImageFormat.Png); } }
public static void SavePng(string tSvg, string tFileName) { MemoryStream tData = new MemoryStream(Encoding.UTF8.GetBytes(tSvg)); Svg.SvgDocument tSvgObj = SvgDocument.Open(tData); MemoryStream tStream = new MemoryStream(); tSvgObj.Draw().Save(tStream, ImageFormat.Png); using (Stream localFile = new FileStream(tFileName, FileMode.OpenOrCreate)) { localFile.Write(tStream.ToArray(), 0, (int)tStream.Length); } }
public void export_png(String tSvg) { string tFileName = "chart"; string tType = "image/png"; MemoryStream tData = new MemoryStream(Encoding.UTF8.GetBytes(tSvg)); MemoryStream tStream = new MemoryStream(); string tExt = "png"; try { Svg.SvgDocument tSvgObj = SvgDocument.Open(tData); tSvgObj.Draw().Save("D:\\PSOG.UI\\chart.bmp", ImageFormat.Bmp); } catch (Exception e) { System.Console.WriteLine(e); } }
//根据svg生成图片 void HuiTu(string tSvg, string strImgPath, string strImg) { strImgPath = System.Web.HttpContext.Current.Server.MapPath(strImgPath); if (!Directory.Exists(strImgPath)) { Directory.CreateDirectory(strImgPath); } MemoryStream tData = new MemoryStream(Encoding.UTF8.GetBytes(tSvg)); MemoryStream tStream = new MemoryStream(); string tTmp = new Random().Next().ToString(); Svg.SvgDocument tSvgObj = SvgDocument.Open(tData); tSvgObj.Draw().Save(tStream, ImageFormat.Jpeg); FileStream fls = new FileStream(strImgPath, FileMode.Create);//创建文件 tStream.WriteTo(fls); tStream.Close(); fls.Close(); }
private void BtnReducir_Click(object sender, EventArgs e) { if (ValidarForm()) { int W = (int)nupAncho.Value; int H = (int)nupAlto.Value; if ((W - 10) > 0 && (H - 10) > 0) { W -= 10; nupAncho.Value = W; H -= 10; nupAlto.Value = H; svgDocument.Width = W; svgDocument.Height = H; pickImagen.Image = svgDocument.Draw(); } } }
public void SaveImage(HttpContext context) { var aa = context.Request.Form["svg"]; if (context.Request.Form["svg"] != null) { string tType = "image/png"; string tSvg = context.Request.Form["svg"].ToString(); string tFileName = ""; Random rand = new Random(24 * (int)DateTime.Now.Ticks); tFileName = rand.Next().ToString(); MemoryStream tData = new MemoryStream(Encoding.UTF8.GetBytes(tSvg)); MemoryStream tStream = new MemoryStream(); string tTmp = new Random().Next().ToString(); string tExt = ""; string tTypeString = ""; switch (tType) { case "image/png": tTypeString = "-m image/png"; tExt = "png"; break; case "image/jpeg": tTypeString = "-m image/jpeg"; tExt = "jpg"; break; case "application/pdf": tTypeString = "-m application/pdf"; tExt = "pdf"; break; case "image/svg+xml": tTypeString = "-m image/svg+xml"; tExt = "svg"; break; } if (tTypeString != "") { //string tWidth = context.Request.Form["width"].ToString(); //string tWidth = "0"; Svg.SvgDocument tSvgObj = SvgDocument.Open(tData); switch (tExt) { case "jpg": tSvgObj.Draw().Save(tStream, ImageFormat.Jpeg); break; case "png": tSvgObj.Draw().Save(tStream, ImageFormat.Png); break; case "pdf": PdfWriter tWriter = null; iTextSharp.text.Document tDocumentPdf = null; try { tSvgObj.Draw().Save(tStream, ImageFormat.Png); tDocumentPdf = new iTextSharp.text.Document(new iTextSharp.text.Rectangle((float)tSvgObj.Width, (float)tSvgObj.Height)); tDocumentPdf.SetMargins(0.0f, 0.0f, 0.0f, 0.0f); iTextSharp.text.Image tGraph = iTextSharp.text.Image.GetInstance(tStream.ToArray()); tGraph.ScaleToFit((float)tSvgObj.Width, (float)tSvgObj.Height); tStream = new MemoryStream(); tWriter = PdfWriter.GetInstance(tDocumentPdf, tStream); tDocumentPdf.Open(); tDocumentPdf.NewPage(); tDocumentPdf.Add(tGraph); tDocumentPdf.CloseDocument(); } catch (Exception ex) { throw ex; } finally { tDocumentPdf.Close(); tDocumentPdf.Dispose(); tWriter.Close(); tWriter.Dispose(); tData.Dispose(); tData.Close(); } break; case "svg": tStream = tData; break; } System.IO.MemoryStream ms = new System.IO.MemoryStream(tStream.ToArray()); System.Drawing.Image image = System.Drawing.Image.FromStream(ms); string savePath = context.Server.MapPath("image/"); if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } savePath += tFileName + "." + tExt; string SavePathImage = tFileName + "." + tExt; context.Session["FirstImage"] = savePath; image.Save(savePath, System.Drawing.Imaging.ImageFormat.Png); image.Dispose(); context.Response.Write(tFileName + "." + tExt); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (Request.Form["type"] != null && Request.Form["svg"] != null && Request.Form["filename"] != null) { string tType = Request.Form["type"].ToString(); string tSvg = Request.Form["svg"].ToString(); tSvg = SvgRemoveHidden(tSvg); tSvg = SvgLine(tSvg); string tFileName = Request.Form["filename"].ToString(); if (tFileName == "") { tFileName = "chart"; } MemoryStream tData = new MemoryStream(Encoding.UTF8.GetBytes(tSvg)); MemoryStream tStream = new MemoryStream(); string tTmp = new Random().Next().ToString(); string tExt = ""; string tTypeString = ""; switch (tType) { case "image/png": tTypeString = "-m image/png"; tExt = "png"; break; case "image/jpeg": tTypeString = "-m image/jpeg"; tExt = "jpg"; break; case "application/pdf": tTypeString = "-m application/pdf"; tExt = "pdf"; break; case "image/svg+xml": tTypeString = "-m image/svg+xml"; tExt = "svg"; break; } if (tTypeString != "") { string tWidth = Request.Form["width"].ToString(); Svg.SvgDocument tSvgObj = SvgDocument.Open(tData); switch (tExt) { case "jpg": tSvgObj.Draw().Save(tStream, ImageFormat.Jpeg); break; case "png": tSvgObj.Draw().Save(tStream, ImageFormat.Png); break; case "pdf": PdfWriter tWriter = null; Document tDocumentPdf = null; try { tSvgObj.Draw().Save(tStream, ImageFormat.Png); tDocumentPdf = new Document(new Rectangle((float)tSvgObj.Width, (float)tSvgObj.Height)); tDocumentPdf.SetMargins(0.0f, 0.0f, 0.0f, 0.0f); iTextSharp.text.Image tGraph = iTextSharp.text.Image.GetInstance(tStream.ToArray()); tGraph.ScaleToFit((float)tSvgObj.Width, (float)tSvgObj.Height); tStream = new MemoryStream(); tWriter = PdfWriter.GetInstance(tDocumentPdf, tStream); tDocumentPdf.Open(); tDocumentPdf.NewPage(); tDocumentPdf.Add(tGraph); tDocumentPdf.CloseDocument(); } catch (Exception ex) { throw ex; } finally { tDocumentPdf.Close(); tDocumentPdf.Dispose(); tWriter.Close(); tWriter.Dispose(); tData.Dispose(); tData.Close(); } break; case "svg": tStream = tData; break; } Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = tType; Response.AppendHeader("Content-Disposition", "attachment; filename=" + tFileName + "." + tExt + ""); Response.BinaryWrite(tStream.ToArray()); Response.Flush(); Response.End(); } } } }
public ActionResult Export(FormCollection fc) { string tType = fc["type"]; string tSvg = fc["svg"]; string tFileName = fc["filename"]; string tWidth = fc["width"]; if (string.IsNullOrEmpty(tFileName)) { tFileName = "DefaultChart"; } MemoryStream tData = new MemoryStream(Encoding.UTF8.GetBytes(tSvg)); Svg.SvgDocument tSvgObj = SvgDocument.Open <SvgDocument>(tData); tSvgObj.Transforms = new SvgTransformCollection(); float scalar = (float)int.Parse(tWidth) / (float)tSvgObj.Width; tSvgObj.Transforms.Add(new SvgScale(scalar, scalar)); tSvgObj.Width = new SvgUnit(tSvgObj.Width.Type, tSvgObj.Width * scalar); tSvgObj.Height = new SvgUnit(tSvgObj.Height.Type, tSvgObj.Height * scalar); MemoryStream tStream = new MemoryStream(); string tTmp = new Random().Next().ToString(); string tExt = ""; switch (tType) { case "image/png": tExt = "png"; break; case "image/jpeg": tExt = "jpg"; break; case "application/pdf": tExt = "pdf"; break; case "image/svg+xml": tExt = "svg"; break; } // Svg.SvgDocument tSvgObj = SvgDocument.Open<SvgDocument>(tData); switch (tExt) { case "jpg": tSvgObj.Draw().Save(tStream, ImageFormat.Jpeg); break; case "png": tSvgObj.Draw().Save(tStream, ImageFormat.Png); break; case "pdf": PdfWriter tWriter = null; Document tDocumentPdf = null; try { tSvgObj.Draw().Save(tStream, ImageFormat.Png); tDocumentPdf = new Document(new iTextSharp.text.Rectangle((float)tSvgObj.Width, (float)tSvgObj.Height)); tDocumentPdf.SetMargins(0.0f, 0.0f, 0.0f, 0.0f); iTextSharp.text.Image tGraph = iTextSharp.text.Image.GetInstance(tStream.ToArray()); tGraph.ScaleToFit((float)tSvgObj.Width, (float)tSvgObj.Height); tStream = new MemoryStream(); tWriter = PdfWriter.GetInstance(tDocumentPdf, tStream); tDocumentPdf.Open(); tDocumentPdf.NewPage(); tDocumentPdf.Add(tGraph); tDocumentPdf.Close(); } catch (Exception ex) { throw ex; } finally { tDocumentPdf.Close(); tWriter.Close(); tData.Dispose(); tData.Close(); } break; case "svg": tStream = tData; break; } tFileName = tFileName + "." + tExt; return(File(tStream.ToArray(), tType, tFileName)); }