use of net.imglib2.display.screenimage.awt.ARGBScreenImage in project imagej-ui-swing by imagej.
the class JHotDrawImageCanvas method capture.
/**
* Captures the current view of data displayed in the canvas, including all
* JHotDraw embellishments.
*/
public Dataset capture() {
final ImageDisplay display = getDisplay();
if (display == null)
return null;
final DatasetView datasetView = imageDisplayService.getActiveDatasetView(display);
if (datasetView == null)
return null;
final ARGBScreenImage screenImage = datasetView.getScreenImage();
final Image pixels = screenImage.image();
final int w = pixels.getWidth(null);
final int h = pixels.getHeight(null);
// draw the backdrop image info
final BufferedImage outputImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
final Graphics2D outputGraphics = outputImage.createGraphics();
outputGraphics.drawImage(pixels, 0, 0, null);
// draw the overlay info
for (final FigureView view : figureViews) {
view.getFigure().draw(outputGraphics);
}
// create a dataset that has view data with overlay info on top
final Dataset dataset = datasetService.create(new long[] { w, h, 3 }, "Captured view", new AxisType[] { Axes.X, Axes.Y, Axes.CHANNEL }, 8, false, false);
dataset.setRGBMerged(true);
final RandomAccess<? extends RealType<?>> accessor = dataset.randomAccess();
for (int x = 0; x < w; x++) {
accessor.setPosition(x, 0);
for (int y = 0; y < h; y++) {
accessor.setPosition(y, 1);
final int rgb = outputImage.getRGB(x, y);
final int r = (rgb >> 16) & 0xff;
final int g = (rgb >> 8) & 0xff;
final int b = (rgb >> 0) & 0xff;
accessor.setPosition(0, 2);
accessor.get().setReal(r);
accessor.setPosition(1, 2);
accessor.get().setReal(g);
accessor.setPosition(2, 2);
accessor.get().setReal(b);
}
}
return dataset;
}
use of net.imglib2.display.screenimage.awt.ARGBScreenImage in project flimj-ui by flimlib.
the class PreviewImageDisplay method setImage.
/**
* Shows an float-valued image, colored by a converter and possibly annotated by a annotator. If
* either of the first two arguments are <code>null</code>, the display will show the
* {@link #PLACEHOLDER_IMAGE}.
*
* @param src The source image
* @param converter The LUT converter
* @param annotator The post-conversion processor functional
*/
public void setImage(final RandomAccessibleInterval<FloatType> src, final RealLUTConverter<FloatType> converter, final ImageAnnotator annotator) {
rawImage = src;
final int oldW = imgW;
final int oldH = imgH;
if (src != null && converter != null) {
imgW = (int) src.dimension(0);
imgH = (int) src.dimension(1);
} else {
imgW = (int) PLACEHOLDER_IMAGE.getWidth();
imgH = (int) PLACEHOLDER_IMAGE.getHeight();
}
// reallocate buffers
if (oldW != imgW || oldH != imgH)
screenImage = new ARGBScreenImage(imgW, imgH);
if (src != null && converter != null) {
coloredImage = Converters.convert(src, converter, new ARGBType());
// convert and annotate image
Cursor<ARGBType> dstCsr = screenImage.localizingCursor();
RandomAccess<ARGBType> lutedRA = coloredImage.randomAccess();
RandomAccess<FloatType> valRA = src.randomAccess();
while (dstCsr.hasNext()) {
dstCsr.fwd();
lutedRA.setPosition(dstCsr);
valRA.setPosition(dstCsr);
dstCsr.get().set(//
annotator != null ? annotator.annotate(valRA, lutedRA) : lutedRA.get());
}
view.setOpacity(1);
clickPane.setVisible(true);
cursor.setVisible(true);
} else {
// show placeholder
SwingFXUtils.fromFXImage(PLACEHOLDER_IMAGE, screenImage.image());
view.setOpacity(0.3);
clickPane.setVisible(false);
cursor.setVisible(false);
}
// resize with parent
Bounds parentBounds = view.getParent().getLayoutBounds();
fitSize(parentBounds.getWidth() - 10, parentBounds.getHeight() - 10);
// force update as content may change
lastReloadPixScale = Double.MIN_VALUE;
reloadImageIfNecessary();
}
Aggregations