Return a byte[] array from Java extension function to JavaScript [message #788036] |
Wed, 01 February 2012 09:18 |
Alessio Pollero Messages: 74 Registered: August 2011 |
Member |
|
|
I have created a functions library that contains some BIRT extension functions, something like this .
I have a problem with a function that return an image as a byte array (byte[]), though the function work properly (the byte array is properly returned), when i assign the byte array result of this function to an image control through the onRender script :
this.data = MyFunctions.getImage();
I get an error datatype not compatible, Why ? How can i make it work ?
[Updated on: Wed, 01 February 2012 09:19] Report message to a moderator
|
|
|
Re: Return a byte[] array from Java extension function to JavaScript [message #789231 is a reply to message #788036] |
Thu, 02 February 2012 19:04 |
|
Have you tried in the onCreate script? I used the following code on an
image example:
importPackage(Packages.java.io);
importPackage(Packages.java.lang);
importPackage(Packages.java.net);
importPackage(Packages.javax.imageio);
//File Based
//var myfile = new Packages.java.io.File("c:/test/green.png");
//var img = ImageIO.read(myfile);
//URL Based
//Jar image in resource folder
//var jarfile = reportContext.getResource("birtimages.jar");
//var myfulljarimagestr = "jar:"+jarfile.toString()+"!/red.png";
//var myurl = new Packages.java.net.URL(myfulljarimagestr);
//Image in resource folder
//var myurl = reportContext.getResource("green.png");
//Image at url
var myurl = new
Packages.java.net.URL("http://www.eclipse.org/eclipse.org-common/themes/Nova/images/eclipse.png");
var img = ImageIO.read(myurl);
bas = new ByteArrayOutputStream();
ImageIO.write(img, "png", bas);
this.data = bas.toByteArray();
Make sure the type is set to dynamic image.
Jason
On 2/1/2012 4:18 AM, Alessio Pollero wrote:
> I have created a function library that contains some BIRT extension
> function, something like
> http://code.google.com/a/eclipselabs.org/p/birt-functions-lib/ .
>
> I have a problem that return an image as a byte array (byte[]), though
> the function work properly (the byte array is properly returned), when i
> assign the byte array result of this function to an image control
> through the onRender script on it :
>
> this.data = MyFunctions.getImage();
>
> I get an error datatype not compatible, Why ? How can i make it work ?
|
|
|
|
Re: Return a byte[] array from Java extension function to JavaScript [message #789957 is a reply to message #789321] |
Fri, 03 February 2012 16:08 |
|
Can you post the code for the getImage function?
Jason
On 2/2/2012 4:23 PM, Alessio Pollero wrote:
> Yes, but the problem is that i load the image with an external function
> written in java, then in the onCreate script i have this code :
> this.data = MyFunctions.getImage();
>
> getImage() is a function into a java jar library (extension functions)
> that return a byte array (byte[]) i get an error as the type is not
> correct, maybe the byte[] is in java format and this.data require it in
> javascript format ? Is it possible to make it work ?
> If i write my code in JAvascript function everything work correctly. but
> i want to have my code into a java exntension library.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03291 seconds