Mathematica 9 is now available
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: [mg53606] Re: Mathematica Graphics output in an ASP.NET WebApplication
  • From: "Hans Michel" <hmichel at sdc.cox.net>
  • Date: Thu, 20 Jan 2005 03:47:47 -0500 (EST)
  • References: <cs5beb$3tt$1@smc.vnet.net> <cs8l5d$emt$1@smc.vnet.net> <csff3t$6ep$1@smc.vnet.net> <csioqa$noo$1@smc.vnet.net>
  • Reply-to: "Hans Michel" <hmichel at sdc.cox.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Javier:

I think you are stuck with using another page as the URL to the image 
element.

I don't think it is a matter of IKernel working or not working. This has 
been the typical way to do dynamic graphics in asp and asp.net. Stick to 
this way it works and workarounds of this solution are messy.

I can think of many work arounds but they may not work with all browser. For 
example you can encode the Image (jpeg) on to a script block or cdata 
section of an embedded xml then call the  image src by using javascript and 
the DOM. But not all browers can render images whose url is javascript 
generated content.

Hans

"Javier Chicote" <goraperas at hotmail.com> wrote in message 
news:csioqa$noo$1 at smc.vnet.net...
> 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: importing mat format doesn't import variable names
  • Next by Date: Re: Parameter Estimation for 3-parameter Weibull Distribution
  • Previous by thread: Re: Mathematica Graphics output in an ASP.NET WebApplication
  • Next by thread: Re: Mathematica is not very clever