What is the picture in the Detail section in the Detail section in JasperReport

xiaoxiao2021-03-06  109

Problem (User ZslzspzsaGD original): I want to pass the picture in the real database in the Detail section (where the path is stored in the server is in the server).

Because I haven't made JasperReport for a long time, just talk about a little idea, wrong, I hope to correct.

First, Detail must need to define a Field:

Note: Class is java.awt.image

Second, it must define your own DataSource

In Public Object GetfieldValue (JRFIELD FIELD) THROWS JREXCEPTION

In the case, if it is the path field of Image, it is loaded back to the picture (should be java.awt.image.bufferedimage).

Such as: public object getfieldValue (Jrfield Field) throws jrexception {

Object value = null; string fieldname = field.getname ();

IF ("image" .Equals (fieldname) {

String imagePath = (take database information according to INDEX and FIELDNAME);

Value = GetImage (imagePath);} else {

...........

}

Return Value;

}

Private BufferedImage GetImage (String ImagePath) {

Image image = Toolkit.getDefaultToolkit () getImage (imagePath);. // Create the buffered image.BufferedImage bufferedImage = new BufferedImage (image.getWidth (null), image.getHeight (null), BufferedImage.TYPE_INT_RGB); // Copy image to buffered image.Graphics g = bufferedImage.createGraphics (); // Clear background and paint the image.g.setColor (Color.white); g.fillRect (0, 0, image.getWidth (null), image.getHeight ( NULL); g.drawImage (image, 0, 0, null); g.dispose (); return bufferedimage;

}

转载请注明原文地址:https://www.9cbs.com/read-125410.html

New Post(0)