Re: how to save a mathematica-made imagebox.image as jpg, gif, bmp in c#/.netlink?

*To*: mathgroup at smc.vnet.net*Subject*: [mg48058] Re: [mg48016] how to save a mathematica-made imagebox.image as jpg, gif, bmp in c#/.netlink?*From*: Oleksandr Pavlyk <pavlyk at phys.psu.edu>*Date*: Mon, 10 May 2004 06:51:14 -0400 (EDT)*Organization*: Penn State University; Department of Physics*References*: <200405070829.EAA24781@smc.vnet.net>*Reply-to*: pavlyk at phys.psu.edu*Sender*: owner-wri-mathgroup at wolfram.com

Not quite related to the question asked, rather some shot in the darkness. If the goal is to save graphics as a file, you could ask Mathematice via NetLink to do so. The following few lines indicate what I mean. IKernelLink ml = MathLinkFactory.CreateKernelLink(); ml.Evaluate("SetDirectory["+ "\"C:/Documents and/Settings/User/Desktop/\""+ "];"); ml.Evaluate("gr = Plot[ Sin[x], {x, 0, 2*Pi}];"); ml.Evaluate("Export[\"test.jpg\",gr, \"JPEG\"]"); ml.Close(); Sasha cdj wrote: > Hi all, > > This has been buggin me for awhile... I'm sure I'm doing something > silly, but I can't figure out what.... > > It suffices to consider the following problem: > > (1) Use the mathematica-supplied c# example (let's you enter a Mathematica > statement, compute, and captures output.) > > How to save a graphicsBox.Image to a file, say as a jpg? > > There's standard code that is available on msdn, to wit: > > (2) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtsksavingfilesusingsavefiledialogcomponent.asp > > When I try to join these 2 bits of code together, I get a totally > uninformative GDI+ error of some sort. > > I'm under the impression that the problem is that the Mathematica graphic > isn't being assigned to the picturebox in the "normal" way, or some > such thing. The reason I have this impression is that while the > following code-bits are quite similar, I can save with one, but not > with the other: > > (a) graphicsBox.Image = mathKernel.Graphics[0]; > > (b) graphicsBox.Image = Image.FromFile("pathtomyfile.jpg"); > > Can anybody explain to me why the msdn routine works fine with (b), > but not with (a)? > > I've been brief here with the description of my problem - I'm happy to > expand a bit on anything above, if it would be helpful.... > > thx much for any insights, > > cdj > -- Office: 6H Osmond Web: http://www.pavlyk.com ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ No trees were destroyed to send this mail, but a lot of electrons were terribly disturbed.

**References**:**how to save a mathematica-made imagebox.image as jpg, gif, bmp in c#/.netlink?***From:*a_cjones@hotmail.com (cdj)