Java 类net.sf.jasperreports.engine.util.JRImageLoader 实例源码

项目:jasperreports    文件:RenderableUtil.java   
/**
 * Creates and returns an instance of the JRImageRenderer class after encoding the image object using an image
 * encoder that supports the supplied image type.
 * 
 * @param image the java.awt.Image object to wrap into a JRImageRenderer instance
 * @param imageType the type of the image as specified by one of the constants defined in the JRRenderable interface
 * @param onErrorType one of the error type constants defined in the {@link OnErrorTypeEnum}.
 * @return the image renderer instance
 */
public Renderable getRenderable(Image image, ImageTypeEnum imageType, OnErrorTypeEnum onErrorType) throws JRException
{
    Renderable result;
    try
    {
        result = new JRImageRenderer(JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(image, imageType));
    }
    catch (Exception e)
    {
        result = handleImageError(e, onErrorType);

        if (log.isDebugEnabled())
        {
            log.debug("handled image error with type " + onErrorType, e);
        }
    }
    return result;
}
项目:jasperreports    文件:RenderableUtil.java   
public Renderable getOnErrorRenderer(OnErrorTypeEnum onErrorType, JRException e) throws JRException
{
    Renderable renderer = null;

    switch (onErrorType)
    {
        case ICON :
        {
            renderer = new JRImageRenderer(JRImageLoader.NO_IMAGE_RESOURCE);
            //FIXME cache these renderers
            break;
        }
        case BLANK :
        {
            break;
        }
        case ERROR :
        default :
        {
            throw e;
        }
    }

    return renderer;
}
项目:jasperreports    文件:RenderableUtil.java   
public Renderable getOnErrorRenderer(OnErrorTypeEnum onErrorType, JRRuntimeException e) throws JRRuntimeException
{
    Renderable renderer = null;

    switch (onErrorType)
    {
        case ICON :
        {
            renderer = new JRImageRenderer(JRImageLoader.NO_IMAGE_RESOURCE);
            //FIXME cache these renderers
            break;
        }
        case BLANK :
        {
            break;
        }
        case ERROR :
        default :
        {
            throw e;
        }
    }

    return renderer;
}
项目:jasperreports    文件:JRPdfExporter.java   
/**
 *
 */
protected Image getPxImage()
{
    if (pxImage == null)
    {
        try
        {
            pxImage =
                Image.getInstance(
                    JRLoader.loadBytesFromResource(JRImageLoader.PIXEL_IMAGE_RESOURCE)
                    );
        }
        catch(Exception e)
        {
            throw new JRRuntimeException(e);
        }
    }

    return pxImage;
}
项目:jasperreports    文件:RendererUtil.java   
/**
 * Creates and returns an instance of the JRImageRenderer class after encoding the image object using an image
 * encoder that supports the supplied image type.
 * 
 * @param image the java.awt.Image object to wrap into a JRImageRenderer instance
 * @param imageType the type of the image as specified by one of the constants defined in the JRRenderable interface
 * @param onErrorType one of the error type constants defined in the {@link OnErrorTypeEnum}.
 * @return the image renderer instance
 */
public Renderable getRenderable(Image image, ImageTypeEnum imageType, OnErrorTypeEnum onErrorType) throws JRException
{
    byte[] data = null;
    try
    {
        data = JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(image, imageType);
    }
    catch (Exception e)
    {
        if (log.isDebugEnabled())
        {
            log.debug("handled image error with type " + onErrorType, e);
        }

        return handleImageError(e, onErrorType);
    }
    return SimpleDataRenderer.getInstance(data);
}
项目:dynamicreports-jasper    文件:Image1Test.java   
@Override
public void test() {
    super.test();

    numberOfPagesTest(1);

    try {
        byte[] imageData = JRImageLoader.getInstance(DefaultJasperReportsContext.getInstance()).loadBytesFromAwtImage(image, ImageTypeEnum.JPEG);
        JRPrintImage jrImage = (JRPrintImage) getElementAt("title.image1", 0);
        Assert.assertTrue("image data", Arrays.equals(imageData, jrImage.getRenderable().getImageData(DefaultJasperReportsContext.getInstance())));
        Assert.assertEquals("scale image", ScaleImageEnum.CLIP, jrImage.getScaleImageValue());
    } catch (JRException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
项目:jasperreports    文件:FileImageProvider.java   
@Override
public Image getImage(JasperReportsContext jasperReportsContext)
{
    try
    {
        return
            JRImageLoader.getInstance(jasperReportsContext).loadAwtImageFromBytes(
                RepositoryUtil.getInstance(jasperReportsContext).getBytesFromLocation(file)
                );
    }
    catch (JRException e)
    {
        throw new JRRuntimeException(e);
    }
}
项目:jasperreports    文件:JRImageRenderer.java   
/**
 *
 */
public Image getImage(JasperReportsContext jasperReportsContext) throws JRException
{
    if (awtImageRef == null || awtImageRef.get() == null)
    {
        Image awtImage = JRImageLoader.getInstance(jasperReportsContext).loadAwtImageFromBytes(getImageData(jasperReportsContext));
        awtImageRef = new SoftReference<Image>(awtImage);
    }
    return awtImageRef.get();
}
项目:jasperreports    文件:WrappingImageDataToGraphics2DRenderer.java   
/**
 *
 */
protected Image getImage(JasperReportsContext jasperReportsContext) throws JRException
{
    if (awtImageRef == null || awtImageRef.get() == null)
    {
        Image awtImage = JRImageLoader.getInstance(jasperReportsContext).loadAwtImageFromBytes(getData(jasperReportsContext));
        awtImageRef = new SoftReference<Image>(awtImage);
    }
    return awtImageRef.get();
}
项目:PDFReporter-Studio    文件:ImageConverter.java   
private Renderable getRenderableNoImage(JasperReportsContext jasperReportsContext, JRImage imageElement,
        JRPrintImage printImage) {
    try {
        printImage.setScaleImage(ScaleImageEnum.CLIP);
        if (noImage == null)
            noImage = RenderableUtil.getInstance(jasperReportsContext).getRenderable(JRImageLoader.NO_IMAGE_RESOURCE,
                    imageElement.getOnErrorTypeValue(), false);
    } catch (Exception e) {
        if (log.isDebugEnabled())
            log.debug("Creating icon renderer for converted image failed.", e);
    }
    return noImage;
}
项目:PDFReporter-Studio    文件:MapDesignConverter.java   
private Renderable getRenderableNoImage(JasperReportsContext jasperReportsContext, MapComponent map,
        JRPrintImage printImage) {
    try {
        printImage.setScaleImage(ScaleImageEnum.CLIP);
        if (noImage == null)
            noImage = RenderableUtil.getInstance(jasperReportsContext).getRenderable(JRImageLoader.NO_IMAGE_RESOURCE,
                    map.getOnErrorType(), false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return noImage;
}
项目:PDFReporter-Studio    文件:LazyImageConverter.java   
/**
 * Return the standard printable element when the image is not found
 * 
 * @param jasperReportsContext the context
 * @param imageElement the actual element
 * @param printImage the print image
 * @return return the not printable element
 */
private Renderable getRenderableNoImage(JasperReportsContext jasperReportsContext, JRImage imageElement,
        JRPrintImage printImage) {
    try {
        printImage.setScaleImage(ScaleImageEnum.CLIP);
        if (noImage == null)
            noImage = RenderableUtil.getInstance(jasperReportsContext).getRenderable(JRImageLoader.NO_IMAGE_RESOURCE,
                    imageElement.getOnErrorTypeValue(), false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return noImage;
}
项目:jasperreports    文件:TextInputComponentDesignConverter.java   
/**
 *
 */
private TextInputComponentDesignConverter()
{
    super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE);//FIXMEINPUT
}
项目:jasperreports    文件:ImageChartRendererFactory.java   
@Override
public Renderable getRenderable(
    JasperReportsContext jasperReportsContext,
    JFreeChart chart, 
    ChartHyperlinkProvider chartHyperlinkProvider,
    Rectangle2D rectangle
    )
{
    int dpi = JRPropertiesUtil.getInstance(jasperReportsContext).getIntegerProperty(Renderable.PROPERTY_IMAGE_DPI, 72);
    double scale = dpi/72d;

    BufferedImage bi = 
        new BufferedImage(
            (int) (scale * (int)rectangle.getWidth()),
            (int) (scale * rectangle.getHeight()),
            BufferedImage.TYPE_INT_ARGB
            );

    List<JRPrintImageAreaHyperlink> areaHyperlinks = null;

    Graphics2D grx = bi.createGraphics();
    try
    {
        grx.scale(scale, scale);

        if (chartHyperlinkProvider != null && chartHyperlinkProvider.hasHyperlinks())
        {
            areaHyperlinks = ChartUtil.getImageAreaHyperlinks(chart, chartHyperlinkProvider, grx, rectangle);
        }
        else
        {
            chart.draw(grx, rectangle);
        }
    }
    finally
    {
        grx.dispose();
    }

    try
    {
        return new SimpleDataRenderer(JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, ImageTypeEnum.PNG), areaHyperlinks);
    }
    catch (JRException e)
    {
        throw new JRRuntimeException(e);
    }
}
项目:jasperreports    文件:JRAbstractSvgRenderer.java   
@Override
public byte[] getImageData(JasperReportsContext jasperReportsContext) throws JRException
{
    Dimension2D dimension = getDimension(jasperReportsContext);
    if (dimension == null)
    {
        throw 
            new JRException(
                EXCEPTION_MESSAGE_KEY_DIMENSION_NULL_NOT_ALLOWED, 
                (Object[])null
                );
    }

    int dpi = getImageDataDPI(jasperReportsContext);
    double scale = dpi/72d;

    ImageTypeEnum imageType = getImageTypeValue();
    BufferedImage bi =
        new BufferedImage(
            (int) (scale * dimension.getWidth()),
            (int) (scale * dimension.getHeight()),
            // avoid creating JPEG images with transparency that would result 
            // in invalid image files for some viewers (browsers)
            (imageType == ImageTypeEnum.GIF || imageType == ImageTypeEnum.PNG)  
                ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB 
            );

    Graphics2D g = createGraphics(bi);
    try
    {
        g.scale(scale, scale);
        Color backcolor = getBackcolor();
        if (backcolor != null)
        {
            g.setColor(backcolor);
            g.fillRect(0, 0, (int)dimension.getWidth(), (int)dimension.getHeight());
        }
        render(jasperReportsContext, g, new Rectangle((int)dimension.getWidth(), (int)dimension.getHeight()));
    }
    finally
    {
        g.dispose();
    }

    return JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, getImageTypeValue());
}
项目:jasperreports    文件:GenericElementConverter.java   
private GenericElementConverter()
{
    super(JRImageLoader.COMPONENT_IMAGE_RESOURCE);
}
项目:jasperreports    文件:SubreportConverter.java   
/**
 *
 */
private SubreportConverter()
{
    super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE);
}
项目:jasperreports    文件:JRXlsExporter.java   
private InternalImageProcessorResult processImageClip(Graphics2DRenderable renderer) throws JRException
{
    int normalWidth = availableImageWidth;
    int normalHeight = availableImageHeight;

    Dimension2D dimension = 
        renderer instanceof DimensionRenderable 
        ? ((DimensionRenderable)renderer).getDimension(jasperReportsContext)
        : null;
    if (dimension != null)
    {
        normalWidth = (int) dimension.getWidth();
        normalHeight = (int) dimension.getHeight();
    }

    int dpi = getPropertiesUtil().getIntegerProperty(Renderable.PROPERTY_IMAGE_DPI, 72);
    double scale = dpi/72d;

    BufferedImage bi = 
        new BufferedImage(
            (int)(scale * availableImageWidth), 
            (int)(scale * availableImageHeight), 
            BufferedImage.TYPE_INT_ARGB
            );

    Graphics2D grx = bi.createGraphics();
    try
    {
        grx.scale(scale, scale);
        grx.clip(
            new Rectangle(
                0,
                0,
                availableImageWidth,
                availableImageHeight
                )
            );

        renderer.render(
            jasperReportsContext,
            grx,
            new Rectangle(
                (int) (ImageUtil.getXAlignFactor(imageElement) * (availableImageWidth - normalWidth)),
                (int) (ImageUtil.getYAlignFactor(imageElement) * (availableImageHeight - normalHeight)),
                normalWidth,
                normalHeight
                )
            );
    }
    finally
    {
        grx.dispose();
    }

    byte[] imageData = null;
    int topOffset = 0;
    int leftOffset = 0;
    int bottomOffset = 0;
    int rightOffset = 0;

    topOffset = topPadding;
    leftOffset = leftPadding;
    bottomOffset = bottomPadding;
    rightOffset = rightPadding;

    imageData = JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, ImageTypeEnum.PNG);

    return new InternalImageProcessorResult(imageData, topOffset, leftOffset, bottomOffset, rightOffset);
}
项目:jasperreports    文件:JRXlsMetadataExporter.java   
private InternalImageProcessorResult processImageClip(Graphics2DRenderable renderer) throws JRException
        {
            int normalWidth = availableImageWidth;
            int normalHeight = availableImageHeight;

            Dimension2D dimension = 
                renderer instanceof DimensionRenderable 
                ? ((DimensionRenderable)renderer).getDimension(jasperReportsContext)
                : null;
            if (dimension != null) {
                normalWidth = (int) dimension.getWidth();
                normalHeight = (int) dimension.getHeight();
            }

            int dpi = getPropertiesUtil().getIntegerProperty(Renderable.PROPERTY_IMAGE_DPI, 72);
            double scale = dpi/72d;

            BufferedImage bi = 
                new BufferedImage(
                    (int)(scale * availableImageWidth), 
                    (int)(scale * availableImageHeight), 
                    BufferedImage.TYPE_INT_ARGB
                    );

            Graphics2D grx = bi.createGraphics();
            try
            {
                grx.scale(scale, scale);
                grx.clip(
                    new Rectangle(
                        0,
                        0,
                        availableImageWidth,
                        availableImageHeight
                        )
                    );

                renderer.render(
                    jasperReportsContext,
                    grx,
                    new Rectangle(
                        (int) (ImageUtil.getXAlignFactor(imageElement) * (availableImageWidth - normalWidth)),
                        (int) (ImageUtil.getYAlignFactor(imageElement) * (availableImageHeight - normalHeight)),
                        normalWidth,
                        normalHeight
                        )
                    );
            }
            finally
            {
                grx.dispose();
            }

            byte[] imageData = null;
            int topOffset = 0;
            int leftOffset = 0;
            int bottomOffset = 0;
            int rightOffset = 0;

//          topOffset = topPadding;
//          leftOffset = leftPadding;
//          bottomOffset = bottomPadding;
//          rightOffset = rightPadding;

            imageData = JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, ImageTypeEnum.PNG);

            return new InternalImageProcessorResult(imageData, topOffset, leftOffset, bottomOffset, rightOffset);
        }
项目:jasperreports    文件:AbstractRenderToImageDataRenderer.java   
@Override
public byte[] getData(JasperReportsContext jasperReportsContext) throws JRException
{
    Dimension2D dimension = getDimension(jasperReportsContext);

    if (dimension == null)
    {
        throw 
            new JRException(
                EXCEPTION_MESSAGE_KEY_DIMENSION_NULL_NOT_ALLOWED, 
                (Object[])null
                );
    }

    int dpi = getImageDataDPI(jasperReportsContext);
    double scale = dpi/72d;

    BufferedImage bi =
        new BufferedImage(
            (int) (scale * dimension.getWidth()),
            (int) (scale * dimension.getHeight()),
            BufferedImage.TYPE_INT_ARGB // always produce PNGs with transparency
            );

    Graphics2D g = createGraphics(bi);
    try
    {
        g.scale(scale, scale);
        Color backcolor = getBackcolor();
        if (backcolor != null)
        {
            g.setColor(backcolor);
            g.fillRect(0, 0, (int)dimension.getWidth(), (int)dimension.getHeight());
        }
        render(jasperReportsContext, g, new Rectangle((int)dimension.getWidth(), (int)dimension.getHeight()));
    }
    finally
    {
        g.dispose();
    }

    return JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, ImageTypeEnum.PNG); // always produce PNGs with transparency
}
项目:jasperreports    文件:MapDesignConverter.java   
/**
 *
 */
private MapDesignConverter()
{
    super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE);
}
项目:jasperreports    文件:SortComponentDesignConverter.java   
/**
 *
 */
private SortComponentDesignConverter()
{
    super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE);
}
项目:jasperreports    文件:IconLabelComponentDesignConverter.java   
/**
 *
 */
private IconLabelComponentDesignConverter()
{
    super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE);//FIXMEINPUT
}
项目:PDFReporter-Studio    文件:MapDesignConverter.java   
/**
 *
 */
private MapDesignConverter() {
    super(JRImageLoader.COMPONENT_IMAGE_RESOURCE);
}
项目:dynamicreports-jasper    文件:GoogleChartsDesignConverter.java   
public GoogleChartsDesignConverter() {
    super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE);
}
项目:jasperreports-wms-component    文件:WmsMapDesignConverter.java   
private WmsMapDesignConverter() {
  super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE);
}