Home » Archived » BIRT » dynamic image with Birt 3.7
dynamic image with Birt 3.7 [message #722673] |
Tue, 06 September 2011 09:41  |
Eclipse User |
|
|
|
Hi there,
i upgraded from BIRT 2.5.2 to BIRT 3.7. I have a dynamic image in one of my reports, which gets its content via a method of a class that returns a byte[]. Works fine with 2.5.2, fails with 3.7.
If i save the byte[] to disk and view the image, everything is fine, are there any changes within the engine i need to know about? (changelog didn't say so)
|
|
| | | | |
Re: dynamic image with Birt 3.7 [message #722929 is a reply to message #722768] |
Wed, 07 September 2011 04:35   |
Eclipse User |
|
|
|
i'm using the RE API, the viewer (the Report Designer) starts but it wont let me "run" the reports. Something is missing/wrong here also.
I'm using a RunAndRenderTask for executing the report within my code, something like this:
public IRunAndRenderTask createTask(URL rptDesignURL){
IRunAndRenderTask task = null;
try {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(ModuleOption.RESOURCE_LOCATOR_KEY, resourceLocator);
design = engine.openReportDesign(null, rptDesignURL.openStream(), map);
task = engine.createRunAndRenderTask(design);
...some catches...
return task;
}
after this, i setup a IRenderOptions object (with attributes outputformat and outputfilename) and set it to the task with:
task.setRenderOption(renderOptions);
finally i start generating the report with:
try {
task.run();
} catch (EngineException e) {
log.error("Could not render design: ", e);
throw new IllegalStateException(e);
}
what am i missing here?
hage
|
|
| | | | | | |
Re: dynamic image with Birt 3.7 [message #726102 is a reply to message #722768] |
Fri, 16 September 2011 11:07   |
Eclipse User |
|
|
|
sorry for replying that late. Posting an event handler isnt that easy, 'cause we're not using any eventhandlers. we have developed our own oda driver and designer addons, so for a query we are using beanshell from which we are calling java classes, that returns, in case of the dynamic image, a byte[].
Beanshell Setup Query (you probably can ignore this):
columns(new String[] { "image" });
inParameters(new String[] { "width", "height" });
Beanshell Query Text:
import ...
c = helper.execute(new ClassA(true));
sag = c.getValue();
chart = new SpiderChart().createChart(sag);
w = new Integer(inpv("width"));
h = new Integer(inpv("height"));
return helper.createImageResult(chart.createBufferedImage(w,h));
"helper" is a static class within our query class in the oda driver project, which supplies some methods to handle the data (in this case, create the byte[] out of the chart (jfreechart)).
createImageResult in Helper class:
public byte[] createImageResult(BufferedImage im) throws IOException
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(im, "png", bos);
return bos.toByteArray();
}
up to the return statement, the byte array contains the image data, i tried to writing that into a file, and everything looks fine. It's just not appearing within the report. Hope you can help me with this.
thx,
hage
|
|
| | | | |
Re: dynamic image with Birt 3.7 [message #726814 is a reply to message #726779] |
Mon, 19 September 2011 11:49   |
Eclipse User |
|
|
|
the code from the report you posted, works. But thats all javascript. My code, as posted above (without the use of js), still doesn't work. I'm currently working on a javascript solution, but that would just be a workaround. i'll try to create a simple example for you to test, later on (but i won't be able to post our whole oda implementation, so i don't know, if you will be able to test that at all, with your setup).
thx in advance,
hage
[Updated on: Mon, 19 September 2011 11:51] by Moderator
|
|
| |
Re: dynamic image with Birt 3.7 [message #727012 is a reply to message #726823] |
Tue, 20 September 2011 03:58  |
Eclipse User |
|
|
|
my js solution/workaround now works. i'll see if i give the java only version any further tries later on, depends on the needs of our customers.
this is how i did it:
// import necessary package for bundle import
importPackage(Packages.org.eclipse.core.runtime);
// import bundles
var samtBundle = Packages.org.eclipse.core.runtime.Platform.getBundle( "abc.xyz.samt.service" );
...
// load classes from bundles
samtClass = samtBundle.loadClass( "abc.xyz.samt.service.SamtClass" );
...
var samtInstance = samtClass.newInstance();
...
//call some methods
var valueA = 5;
samtInstance.setterMethod(valueA);
samtInstance.generateImage();
var result = samtInstance.getImageBytes();
//make result globally available
reportContext.setPersistentGlobalVariable( "ImageBytes", result )
after this, you can access the byte[] via
reportContext.getPersistentGlobalVariable( "ImageBytes" )
in any expression within the report (in the expression of the dynamic image in my case).
(nevertheless, it would be nice to know, if someone gets this byte[] to image thing working without a js, let me know if you do so)
thx for all of your replies and help jason,
hage
[Updated on: Tue, 20 September 2011 04:23] by Moderator
|
|
|
Goto Forum:
Current Time: Tue Jul 22 19:17:21 EDT 2025
Powered by FUDForum. Page generated in 0.06789 seconds
|