レポートに画像を追加

1773 ワード

String embededImgName = "mylogo.bmp";
//EmbededImageの追加

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);

//ImageHandleの追加

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;
	       }