Package com.alibaba.simpleimage

Examples of com.alibaba.simpleimage.SimpleImageException


                return readGIF(input);
            }

            return readGeneral(input);
        } catch (Exception e) {
            throw new SimpleImageException(e);
        }
    }
View Full Code Here


            imageStream = new ImageBitsInputStream(input);
            JPEGDecoder decoder = new JPEGDecoder(imageStream);

            img = decoder.decode();
        } catch (Exception e) {
            throw new SimpleImageException(e);
        }

        return img;
    }
View Full Code Here

            reader.setInput(imageIn);

            int numOfImages = reader.getNumImages(true);
            if(numOfImages <= 0) {
                throw new SimpleImageException("a GIF without pictures inside, maybe it's a attack");
            }
            BufferedImage[] images = new BufferedImage[numOfImages];
            Node[] metadatas = new Node[numOfImages];
            IIOMetadata streamMetadata = reader.getStreamMetadata();
           
            for (int i = 0; i < numOfImages; i++) {
                images[i] = reader.read(i);
                metadatas[i] = reader.getImageMetadata(i).getAsTree(ImageWrapper.GIF_IMAGE_METADATA_NAME);
            }
            ImageWrapper img = new ImageWrapper(images);
            img.setImageFormat(ImageFormat.GIF);
            img.setStreamMetadata(streamMetadata.getAsTree(ImageWrapper.GIF_STREAM_METADATA_NAME));
            img.setMetadatas(metadatas);

            return img;
        } catch (Exception e) {
            throw new SimpleImageException(e);
        } finally {
            if(reader != null){
                reader.dispose();
            }
        }
View Full Code Here

            img = new ImageWrapper(src, DEFAULT_HIGHT_QUALITY);
            img.setImageFormat(format);

            return img;
        } catch (Exception e) {
            throw new SimpleImageException(e);
        }
    }
View Full Code Here

    @Override
    public ImageWrapper render() throws SimpleImageException {
        try {
            ImageWrapper imgWrapper;
            if (inStream == null) {
                throw new SimpleImageException("No input set");
            }

            imgWrapper = ImageReadHelper.read(inStream);

            if (tosRGBColorSpace) {
                for (int i = 0; i < imgWrapper.getNumOfImages(); i++) {
                    PlanarImage img = ImageColorConvertHelper.convert2sRGB(imgWrapper
                            .getAsPlanarImage(i));
                    imgWrapper.setImage(i, img);
                }
            }

            return imgWrapper;
        } catch (Exception e) {
            throw new SimpleImageException(e);
        }
    }
View Full Code Here

            writeGIF(imgWrapper, os, param.getQuantAlgorithm());
        } else if (format == ImageFormat.TIFF || format == ImageFormat.PNG || format == ImageFormat.BMP) {
            try {
                ImageIO.write(imgWrapper.getAsBufferedImage(), format.getDesc(), os);
            } catch (IOException e) {
                throw new SimpleImageException(e);
            }
        } else {
            throw new IllegalArgumentException("Unsupported output format, only JPEG, BMP, GIF, PNG and TIFF are ok");
        }
    }
View Full Code Here

        try {
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os, encodeParam);
            encoder.encode(img);
        } catch (IOException e) {
            throw new SimpleImageException(e);
        } catch (ImageFormatException e) {
            throw new SimpleImageException(e);
        }
    }
View Full Code Here

                if (IndexImageBuilder.needConvertToIndex(images[0])) {
                    img = IndexImageBuilder.createIndexedImage(images[0], quantAlg);
                }
                ImageIO.write(img, "GIF", imageOut);
            } catch (IOException e) {
                throw new SimpleImageException(e);
            } finally {
                ImageUtils.closeQuietly(imageOut);
            }

            return;
        }

        try {
            imageOut = ImageIO.createImageOutputStream(os);
            Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("GIF");
            while (writers.hasNext()) {
                writer = writers.next();
                if (writer.canWriteSequence()) {
                    break;
                }
            }

            if (writer == null || !writer.canWriteSequence()) {
                throw new IllegalStateException("No GIF writer matched");
            }

            writer.setOutput(imageOut);

            ImageWriteParam param = writer.getDefaultWriteParam();
            IIOMetadata streamMeta = writer.getDefaultStreamMetadata(param);
            //merge stream metadata
            streamMeta.mergeTree(ImageWrapper.GIF_STREAM_METADATA_NAME, imgWrapper.getStreamMetadata());
            writer.prepareWriteSequence(streamMeta);
            for (int i = 0; i < images.length; i++) {
                ImageTypeSpecifier imageType = new ImageTypeSpecifier(images[i].getColorModel(),
                                                                      images[i].getSampleModel());
                RenderedImage renderedImg = images[i];
                if (IndexImageBuilder.needConvertToIndex(renderedImg)) {
                    NodeUtils.removeChild(metadatas[i], "LocalColorTable");
                    renderedImg = IndexImageBuilder.createIndexedImage(renderedImg, quantAlg);
                }
                IIOMetadata meta = writer.getDefaultImageMetadata(imageType, param);
                meta.mergeTree(ImageWrapper.GIF_IMAGE_METADATA_NAME, metadatas[i]);

                IIOImage img = new IIOImage(renderedImg, null, meta);
                writer.writeToSequence(img, param);
            }
            writer.endWriteSequence();

            imageOut.flush();
        } catch (IOException e) {
            throw new SimpleImageException(e);
        } finally {
            ImageUtils.closeQuietly(imageOut);

            if (writer != null) {
                writer.dispose();
View Full Code Here

        super(null);
        try {
            this.stream = new FileOutputStream(output);
            this.needClean = true;
        } catch (FileNotFoundException e) {
            throw new SimpleImageException(e);
        }

        this.param = param;
        this.image = image;
        this.outputFormat = format;
View Full Code Here

        super(null);
        try {
            this.stream = new FileOutputStream(output);
            this.needClean = true;
        } catch (FileNotFoundException e) {
            throw new SimpleImageException(e);
        }

        this.image = image;
        this.param = param;
        this.outputFormat = format;
View Full Code Here

TOP

Related Classes of com.alibaba.simpleimage.SimpleImageException

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.