[Date Index]
[Thread Index]
[Author Index]
Re: from Visual Basic To Mathematica through JLink: examples and problems
*To*: mathgroup at smc.vnet.net
*Subject*: [mg26327] Re: from Visual Basic To Mathematica through JLink: examples and problems
*From*: tgayley at wolfram.com (Todd Gayley)
*Date*: Tue, 12 Dec 2000 02:54:42 -0500 (EST)
*Organization*: Wolfram Research, Inc.
*References*: <90v60b$706@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
On 10 Dec 2000 00:57:31 -0500, "rani olam" <okayr9 at cool.com.jo> wrote:
<snip>
>this example is just a demostration , i
>hope VB fans will utilise JLink in connecting to mathematica so they
>will benefit from the powerfull capabilities, and the other people think
>that they are geniuses while they are phoning to mathematica kernel for
>the answers which delivered to them through Jlink underground Cables.
>there is a problem with graphics : How we could plot the function
>Plot[x,{x,0,1}] in a Picture1.Picture or Image1.Image in Visual Basic
>Form ?? every time i get an error.
>Please Help
>rani olam
Rani,
I appreciate your enthusiasm for using J/Link to call Mathematica from Visual Basic.
This is a capability that more people should know about.
As for your question about getting the J/Link method evaluateToImage() to work from VB,
here is an example. The evaluateToImage() command returns (in Java) an array of bytes
containing the GIF data for the image. In VB, this comes in as a Variant array of Long.
The Image control requires you to create a file containing the image--you cannot just
dump an array of data at it. Thus, the technique is to loop through the array,
writing out the elements to a file (after converting them to unsigned bytes).
Please note that my VB skills are weak, so this code could perhaps be written
more simply or efficiently.
' Assume here that width and height are variables that hold the desired
width and height ' for the image, and Image1 is an Image control into
which we want to place the picture.
imageData = link.evaluateToImage("Plot[x,{x,0,1}]", width, height)
Open "plot.gif" For Binary Access Write As #1
For i = 0 To UBound(imageData)
Put #1, , toUnsignedByte(imageData(i))
Next i
Close #1
Image1.Picture = LoadPicture("plot.gif")
Here is the toUnsignedByte function:
Function toUnsignedByte(i) As Byte
If i < 0 Then
toUnsignedByte = CByte(256 + i)
Else
toUnsignedByte = CByte(i)
End If
End Function
Todd Gayley
Wolfram Research
Prev by Date:
**Re:inner angle of a triangle in the 4th dimension**
Next by Date:
**Re: What makes things Listable?**
Previous by thread:
**from Visual Basic To Mathematica through JLink: examples and problems**
Next by thread:
**system of nonlinear differential equations**
| |