Rotating 90º In a Blob Image in JasperReports

会有一股神秘感。 提交于 2019-12-10 10:56:16

问题


So I have a small jrxml with this:

The two images are of the field type BLOB in a firebird database and to show it correctly I'm using new ByteArrayInputStream((byte[])$F{FOFU}) on the image expression.

After reading a bit I figured the only way to rotate this image is to do it programmatically on java and I have no idea how to do, even after reading some posts here and other places. Can anyone help me with this ?


回答1:


private byte[] rotateImage(byte[] originalImageAsBytes , double radians) throws InternalException {
ByteArrayOutputStream rotatedImageStream = null;

try {
  BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(originalImageAsBytes)); // read the original image
  AffineTransform rotationTransform = new AffineTransform();
  rotationTransform.rotate(radians, originalImage.getWidth() / 2.0 , originalImage.getHeight() / 2.0);
  AffineTransformOp rotationTransformOp = 
    new AffineTransformOp(rotationTransform , AffineTransformOp.TYPE_NEAREST_NEIGHBOR); 
  BufferedImage rotatedImage = rotationTransformOp.filter(originalImage,null); 

  rotatedImageStream = new ByteArrayOutputStream();
  ImageIO.write(rotatedImage, "jpg" , rotatedImageStream); 
} catch (IOException e) {
  throw new InternalException(e);
}
return rotatedImageStream.toByteArray();
}

and on the Jasper I'm doing

new ByteArrayInputStream(path.to.rotateImage((byte[])$F{IMAGE}, 100.00))

as the image expression. Its working.



来源:https://stackoverflow.com/questions/19788224/rotating-90%c2%ba-in-a-blob-image-in-jasperreports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!