Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Image By Building byte array in Expression (BIRT)"

(New page: {{Backlink|Report Developer Examples (BIRT)}} This example has no Bugzilla entry.<br> == Introduction == This example demonstrates how to include an image by creating a byte array in an ...)
 
(Description)
 
(5 intermediate revisions by the same user not shown)
Line 8: Line 8:
 
This example has no example attachment.
 
This example has no example attachment.
 
== Description==  
 
== Description==  
BIRT Image controls support URLs, Embedded images within the report, Images
+
BIRT Image elements support URLs, Embedded images within the report, Images
 
from resource folders, and Dynamic images (BLOB) types usually from databases.
 
from resource folders, and Dynamic images (BLOB) types usually from databases.
 
Another way of using the Dynamic image is construct your own byte array within the birt expression.  This can also be done within a Java Event Handler on the image element.
 
Another way of using the Dynamic image is construct your own byte array within the birt expression.  This can also be done within a Java Event Handler on the image element.
 
<br>
 
<br>
When selecting the Dynamic image radial in the Image editor, the expression return value needs to be byte array which contains the data for the image.  As an example the following expression will return a working image.  
+
When selecting the Dynamic image radial in the Image editor, the expression return value needs to be a byte array which contains the data for the image.  As an example the following expression will return a working image. If you are using BIRT 2.2 or greater add the expression to a binding entry.  This can be done by selecting the image element and then select the binding tab.  Select add and enter a name and the expression.  The data type should be set to any.
  
 
  importPackage(Packages.java.io);
 
  importPackage(Packages.java.io);
 
  importPackage(Packages.java.lang);
 
  importPackage(Packages.java.lang);
 
+
 
 
  var file = new File("c:/temp/test.png");
 
  var file = new File("c:/temp/test.png");
 
  var ist = new FileInputStream(file);
 
  var ist = new FileInputStream(file);
 
  var lengthi = file.length();
 
  var lengthi = file.length();
+
 
 
  bytesa = new ByteArrayOutputStream( lengthi);
 
  bytesa = new ByteArrayOutputStream( lengthi);
 
  var c;
 
  var c;
 
  while((c=ist.read()) != -1){
 
  while((c=ist.read()) != -1){
bytesa.write(c);
+
  bytesa.write(c);
 
  }    
 
  }    
 
  ist.close();
 
  ist.close();
 
  bytesa.toByteArray();
 
  bytesa.toByteArray();
 +
 +
 +
If you are using an SWT ImageLoader you can build an expression similar to:
 +
 +
importPackage(Packages.java.io);
 +
importPackage(Packages.java.lang);
 +
importPackage(Packages.org.eclipse.swt.widgets);
 +
importPackage(Packages.org.eclipse.swt.graphics);
 +
importPackage(Packages.org.eclipse.swt);
 +
 +
imgl = new ImageLoader();
 +
imgl.load("c:/temp/test.png");
 +
baos = new ByteArrayOutputStream();
 +
 +
imgl.save(baos, SWT.IMAGE_PNG);
 +
myout = baos.toByteArray();
  
 
== Comments ==  
 
== Comments ==  

Latest revision as of 22:12, 3 August 2007

< To: Report Developer Examples (BIRT)
This example has no Bugzilla entry.

Introduction

This example demonstrates how to include an image by creating a byte array in an expression.

BIRT Version Compatibility

This example was built and tested with BIRT 2.1.2.

Example Files

This example has no example attachment.

Description

BIRT Image elements support URLs, Embedded images within the report, Images from resource folders, and Dynamic images (BLOB) types usually from databases. Another way of using the Dynamic image is construct your own byte array within the birt expression. This can also be done within a Java Event Handler on the image element.
When selecting the Dynamic image radial in the Image editor, the expression return value needs to be a byte array which contains the data for the image. As an example the following expression will return a working image. If you are using BIRT 2.2 or greater add the expression to a binding entry. This can be done by selecting the image element and then select the binding tab. Select add and enter a name and the expression. The data type should be set to any.

importPackage(Packages.java.io);
importPackage(Packages.java.lang);
 
var file = new File("c:/temp/test.png");
var ist = new FileInputStream(file);
var lengthi = file.length();
 
bytesa = new ByteArrayOutputStream( lengthi);
var c;
while((c=ist.read()) != -1){
 		bytesa.write(c);
}	  
ist.close();
bytesa.toByteArray();


If you are using an SWT ImageLoader you can build an expression similar to:

importPackage(Packages.java.io);
importPackage(Packages.java.lang);
importPackage(Packages.org.eclipse.swt.widgets);
importPackage(Packages.org.eclipse.swt.graphics);
importPackage(Packages.org.eclipse.swt);

imgl = new ImageLoader();
imgl.load("c:/temp/test.png");
baos = new ByteArrayOutputStream();
		
imgl.save(baos, SWT.IMAGE_PNG);
myout = baos.toByteArray();

Comments

Please enter comments below by selecting the edit icon to the right. You will need a Bugzilla account to add comments.


Back to the top