Search in sources :

Example 1 with ImageViewport

use of com.revolsys.swing.map.ImageViewport in project com.revolsys.open by revolsys.

the class LayerRendererOverlaySwingWorker method handleBackground.

@Override
protected Void handleBackground() {
    try {
        final Layer layer = this.overlay.getLayer();
        if (layer != null) {
            final Project project = this.overlay.getProject();
            final int imageWidth = this.referencedImage.getImageWidth();
            final int imageHeight = this.referencedImage.getImageHeight();
            if (imageWidth > 0 && imageHeight > 0 && project != null) {
                final BoundingBox boundingBox = this.referencedImage.getBoundingBox();
                try (final ImageViewport viewport = new ImageViewport(project, imageWidth, imageHeight, boundingBox)) {
                    if (layer != null && layer.isExists() && layer.isVisible()) {
                        final LayerRenderer<Layer> renderer = layer.getRenderer();
                        if (renderer != null) {
                            renderer.render(viewport, this);
                        }
                    }
                    if (!isCancelled()) {
                        final BufferedImage image = viewport.getImage();
                        this.referencedImage.setRenderedImage(image);
                    }
                }
            }
        }
        return null;
    } catch (final Throwable t) {
        if (!isCancelled()) {
            Logs.error(this, "Unable to paint", t);
        }
        return null;
    }
}
Also used : Project(com.revolsys.swing.map.layer.Project) ImageViewport(com.revolsys.swing.map.ImageViewport) BoundingBox(com.revolsys.geometry.model.BoundingBox) Layer(com.revolsys.swing.map.layer.Layer) BufferedImage(java.awt.image.BufferedImage)

Example 2 with ImageViewport

use of com.revolsys.swing.map.ImageViewport in project com.revolsys.open by revolsys.

the class SelectRecordsOverlay method refreshImageSelected.

private GeoreferencedImage refreshImageSelected() {
    final Viewport2D viewport = getViewport();
    if (viewport != null) {
        final int width = viewport.getViewWidthPixels();
        final int height = viewport.getViewHeightPixels();
        if (width > 0 && height > 0) {
            try (final ImageViewport imageViewport = new ImageViewport(viewport, BufferedImage.TYPE_INT_ARGB_PRE);
                BaseCloseable transformCloseable = imageViewport.setUseModelCoordinates(true)) {
                final Graphics2D graphics = imageViewport.getGraphics();
                final Project project = getProject();
                refreshImageRenderer(imageViewport, project);
                refreshImageSelectedAndHighlighted(imageViewport, graphics, project);
                return imageViewport.getGeoreferencedImage();
            }
        }
    }
    return null;
}
Also used : Project(com.revolsys.swing.map.layer.Project) Viewport2D(com.revolsys.swing.map.Viewport2D) BaseCloseable(com.revolsys.io.BaseCloseable) ImageViewport(com.revolsys.swing.map.ImageViewport) Point(com.revolsys.geometry.model.Point) Graphics2D(java.awt.Graphics2D)

Example 3 with ImageViewport

use of com.revolsys.swing.map.ImageViewport in project com.revolsys.open by revolsys.

the class EditGeoreferencedImageOverlay method getCachedImage.

private GeoreferencedImage getCachedImage(BoundingBox boundingBox) {
    boundingBox = boundingBox.convert(getViewportGeometryFactory());
    final Viewport2D viewport = getViewport();
    final BoundingBox viewBoundingBox = viewport.getBoundingBox();
    if (this.cachedImage == null || !this.cachedImage.getBoundingBox().equals(viewBoundingBox)) {
        try (final ImageViewport imageViewport = new ImageViewport(viewport)) {
            final BufferedImage image = imageViewport.getImage();
            final Graphics2D graphics = (Graphics2D) image.getGraphics();
            this.image.drawImage(graphics, viewBoundingBox, viewport.getViewWidthPixels(), viewport.getViewHeightPixels(), !this.layer.isShowOriginalImage(), RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            GeoreferencedImageLayerRenderer.render(imageViewport, graphics, this.image, !this.layer.isShowOriginalImage());
            this.cachedImage = new BufferedGeoreferencedImage(imageViewport.getBoundingBox(), image);
        }
    }
    return this.cachedImage;
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) ImageViewport(com.revolsys.swing.map.ImageViewport) BoundingBox(com.revolsys.geometry.model.BoundingBox) BufferedGeoreferencedImage(com.revolsys.raster.BufferedGeoreferencedImage) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

ImageViewport (com.revolsys.swing.map.ImageViewport)3 BoundingBox (com.revolsys.geometry.model.BoundingBox)2 Viewport2D (com.revolsys.swing.map.Viewport2D)2 Project (com.revolsys.swing.map.layer.Project)2 Graphics2D (java.awt.Graphics2D)2 BufferedImage (java.awt.image.BufferedImage)2 Point (com.revolsys.geometry.model.Point)1 BaseCloseable (com.revolsys.io.BaseCloseable)1 BufferedGeoreferencedImage (com.revolsys.raster.BufferedGeoreferencedImage)1 Layer (com.revolsys.swing.map.layer.Layer)1