Package org.apache.xmlgraphics.image.loader

Examples of org.apache.xmlgraphics.image.loader.ImageException


    public Image convert(Image src, Map hints) throws ImageException, IOException {
        checkSourceFlavor(src);
        ImageRendered rendered = (ImageRendered)src;
        ImageWriter writer = ImageWriterRegistry.getInstance().getWriterFor(MimeConstants.MIME_PNG);
        if (writer == null) {
            throw new ImageException("Cannot convert image to PNG. No suitable ImageWriter found.");
        }
        ByteArrayOutputStream baout = new ByteArrayOutputStream();
        ImageWriterParams params = new ImageWriterParams();
        params.setResolution((int)Math.round(src.getSize().getDpiHorizontal()));
        writer.writeImage(rendered.getRenderedImage(), baout, params);
View Full Code Here


                case TIFFImage.COMP_FAX_G3_2D:
                case TIFFImage.COMP_FAX_G4_2D:
                    break;
                default:
                    log.debug("Unsupported compression " + compression);
                    throw new ImageException(
                            "ImageLoader doesn't support TIFF compression: " + compression);
                }
            }
            //Read information used for raw embedding
            fld = dir.getField(TIFFImageDecoder.TIFF_FILL_ORDER);
            if (fld != null) {
                fillOrder = fld.getAsInt(0);
            }

            int stripCount;
            fld = dir.getField(TIFFImageDecoder.TIFF_ROWS_PER_STRIP);
            if (fld == null) {
                stripCount = 1;
            } else {
                stripCount = (int)(info.getSize().getHeightPx() / fld.getAsLong(0));
            }
            if (stripCount > 1) {
                log.debug("More than one strip found in TIFF image.");
                throw new ImageException(
                        "ImageLoader doesn't support multiple strips");
            }
            stripOffset = dir.getField(TIFFImageDecoder.TIFF_STRIP_OFFSETS).getAsLong(0);
            stripLength = dir.getField(TIFFImageDecoder.TIFF_STRIP_BYTE_COUNTS).getAsLong(0);
        } finally {
View Full Code Here

    }

    /** {@inheritDoc} */
    public Image loadImage(ImageInfo info, Map hints, ImageSessionContext session)
            throws ImageException, IOException {
        ImageException firstException = null;
        for (int i = 0, c = this.loaders.length; i < c; i++) {
            ImageLoader loader = this.loaders[i];
            try {
                Image img = loader.loadImage(info, hints, session);
                if (img != null && firstException != null) {
                    log.debug("First ImageLoader failed (" + firstException.getMessage()
                            + "). Fallback was successful.");
                }
                return img;
            } catch (ImageException ie) {
                if (firstException == null) {
View Full Code Here

            if (img.isCacheable()) {
                lastCacheableImage = img;
            }
        }
        if (img == null) {
            throw new ImageException(
                    "Pipeline fails. No ImageLoader and no original Image available.");
        }
       
        if (converterCount > 0) {
            for (int i = startingPoint; i < converterCount; i++) {
View Full Code Here

            } else if (image instanceof ImageGraphics2D) {
                ImageGraphics2D g2dImage = (ImageGraphics2D)image;
                specializedNode = new Graphics2DNode(g2dImage);
            } else {
                ctx.getUserAgent().displayError(
                        new ImageException("Cannot convert an image to a usable format: " + purl));
            }
           
            Rectangle2D imgBounds = getImageBounds(ctx, imageElement);
            Rectangle2D bounds = specializedNode.getPrimitiveBounds();
            float [] vb = new float[4];
View Full Code Here

        //Build the GVT tree
        final GraphicsNode root;
        try {
            root = builder.build(ctx, svg.getDocument());
        } catch (Exception e) {
            throw new ImageException("GVT tree could not be built for SVG graphic", e);
        }

        //Create the painter
        Graphics2DImagePainter painter = new Graphics2DImagePainter() {
View Full Code Here

                case TIFFImage.COMP_FAX_G3_2D:
                case TIFFImage.COMP_FAX_G4_2D:
                    break;
                default:
                    log.debug("Unsupported compression " + compression);
                    throw new ImageException(
                            "ImageLoader doesn't support TIFF compression: " + compression);
                }
            }
            //Read information used for raw embedding
            fld = dir.getField(TIFFImageDecoder.TIFF_FILL_ORDER);
            if (fld != null) {
                fillOrder = fld.getAsInt(0);
            }

            int stripCount;
            fld = dir.getField(TIFFImageDecoder.TIFF_ROWS_PER_STRIP);
            if (fld == null) {
                stripCount = 1;
            } else {
                stripCount = (int)(info.getSize().getHeightPx() / fld.getAsLong(0));
            }
            if (stripCount > 1) {
                log.debug("More than one strip found in TIFF image.");
                throw new ImageException(
                        "ImageLoader doesn't support multiple strips");
            }
            stripOffset = dir.getField(TIFFImageDecoder.TIFF_STRIP_OFFSETS).getAsLong(0);
            stripLength = dir.getField(TIFFImageDecoder.TIFF_STRIP_BYTE_COUNTS).getAsLong(0);
        } finally {
View Full Code Here

            if (img.isCacheable()) {
                lastCacheableImage = img;
            }
        }
        if (img == null) {
            throw new ImageException(
                    "Pipeline fails. No ImageLoader and no original Image available.");
        }

        if (converterCount > 0) {
            for (int i = startingPoint; i < converterCount; i++) {
View Full Code Here

                        }
                        providerIgnoresICC = checkProviderIgnoresICC(reader
                                .getOriginatingProvider());
                        break; //Quit early, we have the image
                    } catch (IndexOutOfBoundsException indexe) {
                        throw new ImageException("Page does not exist. Invalid image index: "
                                + pageIndex);
                    } catch (IllegalArgumentException iae) {
                        //Some codecs like com.sun.imageio.plugins.wbmp.WBMPImageReader throw
                        //IllegalArgumentExceptions when they have trouble parsing the image.
                        throw new ImageException("Error loading image using ImageIO codec", iae);
                    } catch (IIOException iioe) {
                        if (firstException == null) {
                            firstException = iioe;
                        } else {
                            log.debug("non-first error loading image: " + iioe.getMessage());
                        }
                    }
                    try {
                        //Try fallback for CMYK images
                        BufferedImage bi = getFallbackBufferedImage(reader, pageIndex, param);
                        imageData = bi;
                        firstException = null; //Clear exception after successful fallback attempt
                        break;
                    } catch (IIOException iioe) {
                        //ignore
                    }
                    imgStream.reset();
                } finally {
                    reader.dispose();
                }
            }
        } finally {
            ImageUtil.closeQuietly(src);
            //TODO Some codecs may do late reading.
        }
        if (firstException != null) {
            throw new ImageException("Error while loading image: "
                    + firstException.getMessage(), firstException);
        }
        if (imageData == null) {
            throw new ImageException("No ImageIO ImageReader found .");
        }

        ColorModel cm = imageData.getColorModel();

        Color transparentColor = null;
View Full Code Here

    }

    /** {@inheritDoc} */
    public Image loadImage(ImageInfo info, Map hints, ImageSessionContext session)
            throws ImageException, IOException {
        ImageException firstException = null;
        for (int i = 0, c = this.loaders.length; i < c; i++) {
            ImageLoader loader = this.loaders[i];
            try {
                Image img = loader.loadImage(info, hints, session);
                if (img != null && firstException != null) {
                    log.debug("First ImageLoader failed (" + firstException.getMessage()
                            + "). Fallback was successful.");
                }
                return img;
            } catch (ImageException ie) {
                if (firstException == null) {
View Full Code Here

TOP

Related Classes of org.apache.xmlgraphics.image.loader.ImageException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.