shane2004 Posted January 26, 2010 Report Share Posted January 26, 2010 I know I can export chart as a image by doing: chart.Export(FileFormat.Jpeg, @"c:\image.jpg"); But how could I export the image as a service? Basical I want to create a web method which takes all relavent chart settings and dataset and returns a jpeg image to the caller. Thanks Quote Link to comment Share on other sites More sharing options...
Frank Posted January 26, 2010 Report Share Posted January 26, 2010 You can use the RenderToStream method. Check the docs for more info. Quote Link to comment Share on other sites More sharing options...
shane2004 Posted January 27, 2010 Author Report Share Posted January 27, 2010 I can manage to generate the jpg file by using renderStream directly on the page. Basically I use following codes to download the data in excel format from a dataview, any idea I can do similar thing but downloading the image? ============================================================== Response.ClearContent();Response.AddHeader("content-disposition", "attachment; filename=" + strFileName); Response.ContentType = "application/excel";System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); //Instantiate a datagridSystem.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid(); dg.DataSource = dv; dg.DataBind(); //Tell the datagrid to render itself to htmltextwriterdg.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); Quote Link to comment Share on other sites More sharing options...
juanZ Posted February 1, 2010 Report Share Posted February 1, 2010 HiYou can achieve this with the following approach: 1) Get Chart stream (MyStream) using the chart export method. MemoryStream MyStream = new MemoryStream(); MyChart.Export(FileFormat.Jpeg, MyStream); 2) Convert the stream to a base 64 string: MyStream.Position = 0; StreamReader reader = new StreamReader(MyStream); string strBase64 = Convert.ToBase64String(MyStream.ToArray());3) Now you can export this base64 string as the output of your webservice endopint. You can in your excel or any other software, get this base64 str back again into a picture file. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.