import i5d.Image5D;
import ij.*;
import ij.plugin.*;
import ij.process.*;
import ij.measure.*;
/** Converts the current timeframe of an Image5D to an RGB stack using the current 
 * view settings.
 * @author Joachim Walter
 */
public class Image5D_Stack_to_RGB implements PlugIn {

    public void run(String arg) {
        ImagePlus currentImage = WindowManager.getCurrentImage();
        if (currentImage==null) {
            IJ.noImage();
            return;
        }
        if (!(currentImage instanceof Image5D)) {
            IJ.error("Image is not an Image5D.");
            return;
        }
        
        String title = currentImage.getTitle();
        int width = currentImage.getWidth();
        int height = currentImage.getHeight();
        int depth = currentImage.getNSlices();
        int currentSlice = currentImage.getCurrentSlice();
        Calibration cal = currentImage.getCalibration().copy();
        
        
        currentImage.killRoi();
        
        ImagePlus rgbImage = IJ.createImage(title+"-RGB", "RGB black", width, height, 1);
        ImageStack rgbStack = rgbImage.getStack();
        
        for (int i=1; i<=depth; i++) {
            currentImage.setSlice(i);
            currentImage.copy(false);
            
            ImagePlus rgbClip = ImagePlus.getClipboard();
            if (rgbClip.getType()!=ImagePlus.COLOR_RGB)
                new ImageConverter(rgbClip).convertToRGB();
            if (i>1) {
                rgbStack.addSlice(currentImage.getStack().getSliceLabel(i), 
                        rgbClip.getProcessor().getPixels());
            } else {
                rgbStack.setPixels(rgbClip.getProcessor().getPixels(), 1);
                rgbStack.setSliceLabel(currentImage.getStack().getSliceLabel(1), 1);
            }
        }

        currentImage.setSlice(currentSlice);
        rgbImage.setStack(null, rgbStack);
        rgbImage.setSlice(currentSlice);
        rgbImage.setCalibration(cal);
        
        rgbImage.killRoi();
        rgbImage.show();
    }

}

@@ -14,16 +14,18 @@
 age5D;%0D%0A
+%0D%0A
 import i
@@ -26,24 +26,74 @@
 port ij.*;%0D%0A
+import ij.gui.ImageCanvas;%0D%0Aimport ij.measure.*;%0D%0A
 import ij.pl
@@ -123,36 +123,45 @@
 ess.*;%0D%0A
+%0D%0A
 import 
-ij.measure.*;
+java.awt.Graphics;%0D%0A
 %0D%0A/** Co
@@ -1231,77 +1231,473 @@
     
-for (int i=1; i%3C=depth; i++) %7B%0D%0A            currentImage.setSlice(i);
+ImageCanvas canvas = currentImage.getCanvas();%0D%0A        Graphics imageGfx = canvas.getGraphics();%0D%0A        for (int i=1; i%3C=depth; i++) %7B%0D%0A            currentImage.setSlice(i);%0D%0A%0D%0A            // HACK: force immediate (synchronous) repaint of image canvas%0D%0A            if (currentImage instanceof Image5D) %7B%0D%0A              ((Image5D) currentImage).updateImageAndDraw();%0D%0A            %7D%0D%0A            currentImage.updateAndDraw();%0D%0A            canvas.paint(imageGfx);%0D%0A
 %0D%0A  
@@ -2297,16 +2297,45 @@
       %7D%0D
+%0A        imageGfx.dispose();%0D
 %0A%0D%0A     

Fix asynchronous painting bug with "Image5D Stack to RGB" command.