Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » image programmatically
image programmatically [message #255909] Fri, 21 September 2007 11:07 Go to next message
Parvez is currently offline ParvezFriend
Messages: 181
Registered: July 2009
Senior Member
Hi,

I have an image item in report and want to set/create it programmatically.

<image name="someImage" id="16">
<property
name="eventHandlerClass">MyImageEventHandler</property>
</image>

On image event handler (MyImageEventHandler -> IImageEventHandler), I am
doing something like this:


@Override
public void onRender(IImageInstance image, IReportContext reportContext)
{

byte[] imageBuffer = .....
image.setData(imageBuffer);

}

Though this method executes but in the end, report doesn't contain any
image. I am just wondering, do I have to something more or may be in
some different way?

Any suggestions?

Thanks.
Re: image programmatically [message #255918 is a reply to message #255909] Fri, 21 September 2007 16:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

PC,

What selection did you use (URI, file, Embedded, dynamic?)

If you are using a byte array in 2.2 this should be set to dynamic, URI
will not work.

Here is an example of a test image handler.

I put this in for my settings for the image
<image id="60">
<property name="eventHandlerClass">myImageHandler</property>
<property name="source">expr</property>
<expression name="valueExpr">row["dummy"]</expression>
</image>

Jason


import
org.eclipse.birt.report.engine.api.script.eventadapter.Image EventAdapter;
import org.eclipse.birt.report.engine.api.script.instance.IImageIns tance;
import org.eclipse.birt.report.engine.api.script.IReportContext;
import java.io.*;


public class myImageHandler extends ImageEventAdapter {

@Override
public void onCreate(IImageInstance image, IReportContext reportContext) {

try{
File file = new File("c:/temp/test.png");
FileInputStream ist = new FileInputStream(file);
int lengthi = (int)file.length();

ByteArrayOutputStream bytesa = new ByteArrayOutputStream( lengthi);
int c;
while((c=ist.read()) != -1){
bytesa.write(c);
}
ist.close();
image.setData(bytesa.toByteArray());
}catch( Exception e){
e.printStackTrace();
}

}

@Override
public void onRender(IImageInstance image, IReportContext reportContext) {
// TODO Auto-generated method stub
super.onRender(image, reportContext);
}

}


PC wrote:
> Hi,
>
> I have an image item in report and want to set/create it programmatically.
>
> <image name="someImage" id="16">
> <property
> name="eventHandlerClass">MyImageEventHandler</property>
> </image>
>
> On image event handler (MyImageEventHandler -> IImageEventHandler), I am
> doing something like this:
>
>
> @Override
> public void onRender(IImageInstance image, IReportContext reportContext)
> {
>
> byte[] imageBuffer = .....
> image.setData(imageBuffer);
>
> }
>
> Though this method executes but in the end, report doesn't contain any
> image. I am just wondering, do I have to something more or may be in
> some different way?
>
> Any suggestions?
>
> Thanks.
Re: image programmatically [message #255926 is a reply to message #255918] Fri, 21 September 2007 17:16 Go to previous message
Parvez is currently offline ParvezFriend
Messages: 181
Registered: July 2009
Senior Member
Thanks Jason.

I am using BIRT 2.2.
I was not using source in image i.e. no source like expr, I thought I
don't need it, if I am seting programmatically.

Now, as per your suggestion I have changed it to:

<image name="someImage" id="16">
<property name="eventHandlerClass">myImageHandler</property>
<property name="source">expr</property>
<expression name="valueExpr">"dummy"</expression>
</image>

and it worked.

I didn't use row otherwise it was complaining about row variable, but
that also worked as per:

<image name="someImage" id="16">
<property name="eventHandlerClass">myImageHandler</property>
<method name="onPrepare"><![CDATA[var row = 0;]]></method>
<property name="source">expr</property>
<expression name="valueExpr">row["dummy"]</expression>
</image>

Thanks for your time & help.

Jason Weathersby wrote:
> PC,
>
> What selection did you use (URI, file, Embedded, dynamic?)
>
> If you are using a byte array in 2.2 this should be set to dynamic, URI
> will not work.
>
> Here is an example of a test image handler.
>
> I put this in for my settings for the image
> <image id="60">
> <property name="eventHandlerClass">myImageHandler</property>
> <property name="source">expr</property>
> <expression name="valueExpr">row["dummy"]</expression>
> </image>
>
> Jason
>
>
> import
> org.eclipse.birt.report.engine.api.script.eventadapter.Image EventAdapter;
> import org.eclipse.birt.report.engine.api.script.instance.IImageIns tance;
> import org.eclipse.birt.report.engine.api.script.IReportContext;
> import java.io.*;
>
>
> public class myImageHandler extends ImageEventAdapter {
>
> @Override
> public void onCreate(IImageInstance image, IReportContext
> reportContext) {
>
> try{
> File file = new File("c:/temp/test.png");
> FileInputStream ist = new FileInputStream(file);
> int lengthi = (int)file.length();
>
> ByteArrayOutputStream bytesa = new ByteArrayOutputStream( lengthi);
> int c;
> while((c=ist.read()) != -1){
> bytesa.write(c);
> }
> ist.close();
> image.setData(bytesa.toByteArray());
> }catch( Exception e){
> e.printStackTrace();
> }
>
> }
>
> @Override
> public void onRender(IImageInstance image, IReportContext
> reportContext) {
> // TODO Auto-generated method stub
> super.onRender(image, reportContext);
> }
>
> }
>
>
> PC wrote:
>> Hi,
>>
>> I have an image item in report and want to set/create it
>> programmatically.
>>
>> <image name="someImage" id="16">
>> <property
>> name="eventHandlerClass">MyImageEventHandler</property>
>> </image>
>>
>> On image event handler (MyImageEventHandler -> IImageEventHandler), I
>> am doing something like this:
>>
>>
>> @Override
>> public void onRender(IImageInstance image, IReportContext
>> reportContext)
>> {
>>
>> byte[] imageBuffer = .....
>> image.setData(imageBuffer);
>>
>> }
>>
>> Though this method executes but in the end, report doesn't contain any
>> image. I am just wondering, do I have to something more or may be in
>> some different way?
>>
>> Any suggestions?
>>
>> Thanks.
Previous Topic:Authenticated Web Services data source
Next Topic:Integrate Birt Excel
Goto Forum:
  


Current Time: Wed Jan 15 13:08:06 GMT 2025

Powered by FUDForum. Page generated in 0.03720 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top