Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Mathematica Graphics output in an ASP.NET WebApplication

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53571] Re: Mathematica Graphics output in an ASP.NET WebApplication
  • From: "Javier Chicote" <goraperas at hotmail.com>
  • Date: Tue, 18 Jan 2005 05:08:25 -0500 (EST)
  • References: <cs5beb$3tt$1@smc.vnet.net> <cs8l5d$emt$1@smc.vnet.net> <csff3t$6ep$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Hans,

Thank you very much for your answer, now I can understand why
"mathKernel.Link.EvaluateToImage" works but "mathKernel.Graphics" doesn't,
with the explanation that Todd gives. However, I haven't found yet the
solution for my problem, even if I point the Image to a new Bitmap object.

(1) This is the solution that works, but I don't want to use the
"mathKernel.Link.EvaluateToImage" method:

System.Drawing.Image img = mathKernel.Link.EvaluateToImage(input,200,200);
img.Save(Response.OutputStream, ImageFormat.Jpeg);

(2) This was the solution that I thought, which doesn't work:

System.Drawing.Image img = mathKernel.Graphics[0];
img.Save(Response.OutputStream, ImageFormat.Jpeg);

(3) If I point the image to a new Bitmap it doesn't work:

Bitmap bmp = new Bitmap(mathKernel.Graphics[0]);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);

(4) I thought that maybe I should convert the Bitmap into a Image, but It
doen't work neither:

Bitmap bmp= new Bitmap(mathKernel.Graphics[0]);
System.Drawing.Image img = bmp;
img.Save(Response.OutputStream, ImageFormat.Jpeg);

Do you know what I should modify in the (3) or (4) solutions to see the
Image? Maybe

Do you know what I should modify in the (3) or (4) solutions to see the
Image? Maybe they don't work because I'm using a Web Application instead of
a Windows Application, and because of that I cannot use the graphicBox that
Todd says and I must do the trick of using a WebForm2 as a Image. Anyway, if
the solution (1) works perfectly I cannot understand why solution (3)
doesn't.

Regards,

Javier


"Hans Michel" <hmichel at sdc.cox.net> escribió en el mensaje
news:csff3t$6ep$1 at smc.vnet.net...
> Javier:
>
> Please see this previous thread from the newsgroup.
>
>   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
> >>
> >
> >
>



  • Prev by Date: Re: LegendreP -- up to which order?
  • Next by Date: Matrix Problem
  • Previous by thread: Re: Mathematica Graphics output in an ASP.NET WebApplication
  • Next by thread: Re: Mathematica Graphics output in an ASP.NET WebApplication