为报表添加图片

String embededImgName = "mylogo.bmp";

[b]//添加EmbededImage[/b]

EmbeddedImage image = StructureFactory.createEmbeddedImage();
image.setType(DesignChoiceConstants.IMAGE_TYPE_IMAGE_BMP);//IMAGE_TYPE_IMAGE_JPEG);
InputStream is = this.getClass().getClassLoader().getResourceAsStream("/icons/"+名字);
image.setData(load(is));
image.setName(名字);
designHandle.addImage(image);



[b]//添加ImageHandle[/b]

ImageHandle image1 = efactory.newImage("Logo");
GridHandle grid = efactory.newGridItem("", 1, 1);
designHandle.getBody().add(grid);
grid.setWidth("100%");
RowHandle gridRow = (RowHandle) grid.getRows().get(0);
CellHandle gridCell = (CellHandle) gridRow.getCells().get(0);
image1.setImageName(名字);
gridCell.getContent().add(image1);
gridCell.setProperty(StyleHandle.TEXT_ALIGN_PROP, DesignChoiceConstants.TEXT_ALIGN_CENTER );


加载方法


public byte[] load(InputStream is) throws IOException {
byte data[] = null;
if (is != null) {
try {
int length = is.available();
data = new byte[length];
int offset = 0;
while (offset < data.length) {
int a = is.available();
int bytesRead = is.read(data, offset, a);
if (bytesRead == -1) {
break; // end of stream
}
offset += bytesRead;
}
} catch (IOException e1) {
throw e1;
}finally{
is.close();
}
}
return data;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值