Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Return a byte[] array from Java extension function to JavaScript
Return a byte[] array from Java extension function to JavaScript [message #788036] Wed, 01 February 2012 04:18 Go to next message
Alessio Pollero is currently offline Alessio Pollero
Messages: 66
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 04: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 14:04 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

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 #789321 is a reply to message #789231] Thu, 02 February 2012 16:23 Go to previous messageGo to next message
Alessio Pollero is currently offline Alessio Pollero
Messages: 66
Registered: August 2011
Member
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.
Re: Return a byte[] array from Java extension function to JavaScript [message #789957 is a reply to message #789321] Fri, 03 February 2012 11:08 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

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.
Re: Return a byte[] array from Java extension function to JavaScript [message #790446 is a reply to message #789957] Sat, 04 February 2012 03:47 Go to previous messageGo to next message
Alessio Pollero is currently offline Alessio Pollero
Messages: 66
Registered: August 2011
Member
It was a stupid mistake into the function, now it's working.

Thanks anyway.
Re: Return a byte[] array from Java extension function to JavaScript [message #895457 is a reply to message #790446] Fri, 13 July 2012 02:01 Go to previous message
karthik singavel is currently offline karthik singavel
Messages: 1
Registered: July 2012
Junior Member
Hi Alessio, Iam also facing same problem. Can you please share your code.
Previous Topic:How to display table based on dynamic table name
Next Topic:How to get chart legend value as an input in parameter of target report
Goto Forum:
  


Current Time: Thu Aug 21 16:08:48 EDT 2014

Powered by FUDForum. Page generated in 0.05320 seconds