/** * Constructs multi-dimensional grid envelope defined by a {@link RenderedImage}. The two first * dimensions are set to the [{@linkplain RenderedImage#getMinX x} .. x+{@linkplain * RenderedImage#getWidth width}-1] and [{@linkplain RenderedImage#getMinY y} .. y+{@linkplain * RenderedImage#getHeight height}-1] inclusive ranges respectively. Extra dimensions (if any) * are set to the [0..0] inclusive range. * * <p>Notice that this method ensure interoperability between {@link Raster} dimensions in * Java2D style and {@link GridEnvelope} dimensions in ISO 19123 style providing that the user * remember to add 1 to the {@link GridEnvelope#getHigh(int)} values. * * @param image The image for which to construct a grid envelope. * @param dimension Number of dimensions for this grid envelope. Must be equals or greater than * 2. */ public GeneralGridEnvelope(final RenderedImage image, final int dimension) { this(image.getMinX(), image.getMinY(), image.getWidth(), image.getHeight(), dimension); }
private Component titledImagePanel(String string, RenderedImage expected) { JPanel panel = new JPanel(new BorderLayout()); final JLabel title = new JLabel(string); title.setAlignmentX(0.5f); title.setBorder(new LineBorder(Color.BLACK)); panel.add(title, BorderLayout.NORTH); panel.add( new ScrollingImagePanel( expected, Math.min(400, expected.getWidth()), Math.min(400, expected.getHeight())), BorderLayout.CENTER); return panel; }
/** Displays the specified image in a window with the specified title. */ @SuppressWarnings("deprecation") public Viewer(final String title, final RenderedImage image) { final int width = Math.max(Math.min(image.getWidth(), 800), 24); final int height = Math.max(Math.min(image.getHeight(), 600), 24); frame = new Frame(title); frame.add(new javax.media.jai.widget.ScrollingImagePanel(image, width, height)); frame.addWindowListener(this); EventQueue.invokeLater(this); }
static int typeFromImage(final RenderedImage image, final String compression) { int width = image.getWidth(); int height = image.getHeight(); if (width == height) { switch (compression) { case "JPEG2000": case "PNG": return typeFromWidthForeign(width); case "None": case "RLE": return typeFromWidthNative(width); default: throw new IllegalArgumentException("Unsupported compression for ICNS: " + compression); } } // Note: Strictly, the format supports an ancient 16x12 size, but I doubt we'll ever support that throw new IllegalArgumentException(String.format("Unsupported dimensions for ICNS, only square icons supported: %dx%d", width, height)); } // NOTE: These also needs a mask, if there's an alpha channel
/** * Computes the sub-mosaic spatial extend based on the image size and the target grid to world * transformation * * @param mosaicProducer * @param image * @return * @throws FactoryException */ private ReferencedEnvelope computeSubmosaicBoundingBox( MathTransform2D tx, RenderedImage image, CoordinateReferenceSystem crs) throws FactoryException { double[] mosaicked = new double[] { image.getMinX(), image.getMinY(), image.getMinX() + image.getWidth(), image.getMinY() + image.getHeight() }; try { tx.transform(mosaicked, 0, mosaicked, 0, 2); } catch (TransformException e) { throw new FactoryException(e); } ReferencedEnvelope submosaicBBOX = new ReferencedEnvelope(mosaicked[0], mosaicked[2], mosaicked[1], mosaicked[3], crs); return submosaicBBOX; }
/** * Add the image to the movie. * <p/> * The image size needs to be exactly the same size as the movie. * <p/> * Internally, this saves the image to a temporary image and increases the frame counter. Temporary images are * cleaned up when calling save() or if an error occurs. * * @param img the image to add to the movie. */ public void addFrame(RenderedImage img) { if (img.getWidth() != width || img.getHeight() != height) { throw new RuntimeException("Given image does not have the same size as the movie."); } try { ImageIO.write(img, "png", temporaryFileForFrame(frameCount)); frameCount++; } catch (IOException e) { cleanupAndThrowException(e); } }
private ROI getImageBoundsROI(RenderedImage image) { final int minX = image.getMinX(); final int minY = image.getMinY(); final int maxX = minX + image.getWidth(); final int maxY = minY + image.getHeight(); LiteCoordinateSequence cs = new LiteCoordinateSequence( minX, minY, maxX, minY, maxX, maxY, minX, maxY, minX, minY); Geometry footprint = new GeometryFactory().createPolygon(cs); return new ROIGeometry(footprint); }
/** * Constructs an <code>RasterLayout</code> with all its parameters set to equal those of a given * <code>RenderedImage</code>. * * @param im a <code>RenderedImage</code> whose layout will be copied. */ public RasterLayout(RenderedImage im) { this( im.getMinX(), im.getMinY(), im.getWidth(), im.getHeight(), im.getTileGridXOffset(), im.getTileGridYOffset(), im.getTileWidth(), im.getTileHeight()); }
/** * Post processes a blank image response, eventually making it transparent * * @param finalImage * @return */ public RenderedImage postProcessBlankResponse(RenderedImage finalImage, RenderingHints hints) { // prepare a ROI made of only zeroes ImageLayout layout = new ImageLayout( finalImage.getMinX(), finalImage.getMinY(), finalImage.getWidth(), finalImage.getHeight()); RenderedOp roi = ConstantDescriptor.create( (float) finalImage.getWidth(), (float) finalImage.getHeight(), new Byte[] {0}, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); ImageWorker iw = new ImageWorker(finalImage); iw.setROI(new ROI(roi)); return iw.getRenderedImage(); } }
/** * Gets pixel data of an <code>RenderedImage</code> object. * * @param image an <code>RenderedImage</code> object * @return a byte buffer of pixel data */ public static ByteBuffer getImageByteBuffer(RenderedImage image) { ColorModel cm = image.getColorModel(); WritableRaster wr = image.getData().createCompatibleWritableRaster(image.getWidth(), image.getHeight()); image.copyData(wr); BufferedImage bi = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null); return convertImageData(bi); }
/** * Computes the image size based on the SampleModel and image dimension * * @param image * @return */ static long computeImageSize(RenderedImage image) { long bits = 0; final int bands = image.getSampleModel().getNumBands(); for (int i = 0; i < bands; i++) { bits += image.getSampleModel().getSampleSize(i); } return (long) Math.ceil(bits / 8) * image.getWidth() * image.getHeight(); }