Re: Mathematica Graphics output in an ASP.NET WebApplication
- To: mathgroup at smc.vnet.net
- Subject: [mg53542] Re: Mathematica Graphics output in an ASP.NET WebApplication
- From: "Hans Michel" <hmichel at sdc.cox.net>
- Date: Sun, 16 Jan 2005 22:23:59 -0500 (EST)
- References: <cs5beb$3tt$1@smc.vnet.net> <cs8l5d$emt$1@smc.vnet.net>
- Reply-to: "Hans Michel" <hmichel at sdc.cox.net>
- Sender: owner-wri-mathgroup at wolfram.com
Javier: Please see this previous thread from the newsgroup. [mg48059] Re: [mg48016] how to save a mathematica-made imagebox.image as jpg, gif, bmp in c#/.netlink? Todd Gayley give a good explanation why this error happens. I have been using the work around for some time. Point the Image to a new Image (Bitmap) object. Hans "Javier Chicote" <goraperas at hotmail.com> wrote in message news:cs8l5d$emt$1 at smc.vnet.net... > Hello Hans, > > Thank you very much for your response, now I can see the image in my > application, although I still have a problem: > > I would like the use the "mathKernel.Compute" and "mathKernel.Graphics" > methods in my application, but I must use the > "mathKernel.Link.EvaluateToImage" method to see the image. Do you know why > does [#1] work and [#2] doesn't in the following code?? As far as I know, > both EvaluateToImage and mathKernel.Graphic[0] methods return an > System.Drawing.Image object. > > private void Page_Load(object sender, System.EventArgs e) > { > mathKernel = new Wolfram.NETLink.MathKernel(); > string path = "C:/Archivos de programa/Wolfram > Research/Mathematica/5.0/mathkernel.exe"; > mathKernel.LinkArguments = "-linkmode launch -linkname \"" + path + > "\""; > mathKernel.Connect(); > mathKernel.GraphicsHeight=200; > mathKernel.GraphicsWidth=200; > string input = "Plot3D[Sin[x y], {x, -Pi, Pi}, {y, 0 ,10}]"; > > // #1 This works OK :) > System.Drawing.Image img = > mathKernel.Link.EvaluateToImage(input,200,200); > > // #2 This does NOT work :( > // mathKernel.Compute(input); > // System.Drawing.Image img = mathKernel.Graphics[0]; > > img.Save(Response.OutputStream, ImageFormat.Jpeg); > mathKernel.Dispose(); > } > > Regards, > > Javier > > > <hmichel at cox.net> escribió en el mensaje news:cs5beb$3tt$1 at smc.vnet.net... >> Javier Chicote >> >> You are streaming a jpeg image to the image element with src attribute >> url > Webform2.aspx in WebForm1.aspx page. >> >> The image you stream must be for lack of a better term well formed. Now >> if > you were to take a jpeg image and add html text tag or any extraneous > characters to that file most programs may not know how to render it. This > is > what is happening on WebForm2.aspx. You have extraneous characters. >> >> Remove the DOCTYPE Declaration. No HTML or anything except for the page > directive. Response stream must be neat. >> >> Just >> "<%@ Page lan .... %>" >> >> WebForm2 >> ============================================================ >> >> <%@ Page language="c#" Codebehind="WebForm2.aspx.cs" > AutoEventWireup="false" >> Inherits="mathGraph.WebForm2" EnableSessionState="False" >> enableViewState="False" contentType="image/jpeg"%> >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > >> >> Remove the preceding document type declaration >> Hans >> > >