Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*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 2006

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

Search the Archive

Re: .NET/Link and two-dimensional strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67116] Re: .NET/Link and two-dimensional strings
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Fri, 9 Jun 2006 01:09:41 -0400 (EDT)
  • References: <e63msq$kqp$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

colin wrote:
> The following two lines export a jpeg file containing RED text when
> executed in a notebook:
> 
> myText="\!\(\*StyleBox[\"my text\",\nFontColor->RGBColor[1, 0, 0]]\)";
> Export["C:\\Temp\\myText.jpg",Show[Graphics[Text[myText,{0,0}]]]];
> 
> If I put these same lines in a file called myText.txt, and then read
> this file with the following .NET code, the kernel produces a jpeg file
> containing BLACK text.
> 
> using System;
> using System.IO;
> using Wolfram.NETLink;
> 
> namespace WriTest
> {
>     static class Program
>     {
>          static void Main()
>         {
>             MathKernel mathKernel = new MathKernel();
> 
>             StreamReader streamReader = new
> StreamReader(@"C:\Temp\myFile.txt");
>             string command1 = streamReader.ReadLine();
>             string command2 = streamReader.ReadLine();
>             streamReader.Close();
> 
>             mathKernel.Compute(command1);
>             string result1 = mathKernel.Result.ToString();
> 
>             mathKernel.Compute(command2);
>             string result2 = mathKernel.Result.ToString();
>        }
>     }
> }
> 
> Note an examination of command1 within the debugger, just before it is
> sent to the kernel, produces the following string:
> 
> "myText=\"\\!\\(\\*StyleBox[\\\"my text\\\",\\nFontColor->RGBColor[1,
> 0, 0]]\\)\";"
> 
> Wrapping ToExpression around this string in a Mathematica notebook
> results in the desired red text. This problem seems to be related to
> the need for the StyleBox which can only be found in a two-dimensional
> string.  Other two dimensional string also lead to problems.
> 
> What is my problem?
> 
> 
>     Colin
> 
I am much more familiar with J/Link rather than .NET/Link, but the point 
is that you can't expect strings containing 2-D expressions and/or 
font/style changes to work in .NET. I suggest you use Export to convert 
your string (or the expression that it represents) into a GIF file, and 
then pass that to .NET/Link and use it as an image.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: Using a list as a variable
  • Next by Date: Re: Re: Two questions (1) Sollve and (2) Precision
  • Previous by thread: .NET/Link and two-dimensional strings
  • Next by thread: Re: .NET/Link and two-dimensional strings