private BufferedImage createThumbNailImage(Dimension imgSize, ProgressMonitor pm) { Assert.notNull(pm, "pm"); String thumbNailBandName = getThumbnailBandName(); Band thumbNailBand = product.getBand(thumbNailBandName); Debug.trace( "ProductSubsetDialog: Reading thumbnail data for band '" + thumbNailBandName + "'..."); pm.beginTask("Creating thumbnail image", 5); BufferedImage image = null; try { MultiLevelSource multiLevelSource = BandImageMultiLevelSource.create(thumbNailBand, SubProgressMonitor.create(pm, 1)); final ImageLayer imageLayer = new ImageLayer(multiLevelSource); final int imageWidth = imgSize.width; final int imageHeight = imgSize.height; final int imageType = BufferedImage.TYPE_3BYTE_BGR; image = new BufferedImage(imageWidth, imageHeight, imageType); Viewport snapshotVp = new DefaultViewport(isModelYAxisDown(imageLayer)); final BufferedImageRendering imageRendering = new BufferedImageRendering(image, snapshotVp); final Graphics2D graphics = imageRendering.getGraphics(); graphics.setColor(getBackground()); graphics.fillRect(0, 0, imageWidth, imageHeight); snapshotVp.zoom(imageLayer.getModelBounds()); snapshotVp.moveViewDelta(snapshotVp.getViewBounds().x, snapshotVp.getViewBounds().y); imageLayer.render(imageRendering); pm.worked(4); } finally { pm.done(); } return image; }
@Override public synchronized void nodeChanged(ProductNodeEvent event) { final ProductNode sourceNode = event.getSourceNode(); if (sourceNode instanceof Mask) { final Mask mask = (Mask) sourceNode; final ImageLayer maskLayer = getMaskLayer(mask); if (maskLayer != null) { if (event.getPropertyName().equals("name")) { maskLayer.setName(mask.getName()); } else { maskLayer.regenerate(); } } } }
public static void displayImage( File location, String extension, AffineTransform imageToModelTransform, int levelCount) { final LayerCanvas layerCanvas = new LayerCanvas(); installLayerCanvasNavigation(layerCanvas); final Layer collectionLayer = layerCanvas.getLayer(); final MultiLevelSource source = FileMultiLevelSource.create(location, extension, imageToModelTransform, levelCount); final ImageLayer layer = new ImageLayer(source); collectionLayer.getChildren().add(layer); final Rectangle viewportBounds = new Rectangle(0, 0, 640, 480); layerCanvas.setPreferredSize(new Dimension(640, 480)); layerCanvas.getViewport().setViewBounds(viewportBounds); layerCanvas.getViewport().zoom(layer.getModelBounds()); openFrame(layerCanvas, location.getPath(), viewportBounds); }
private boolean isModelYAxisDown(ImageLayer baseImageLayer) { return baseImageLayer.getImageToModelTransform().getDeterminant() > 0.0; }