I've encountered a behaviour change where my code works in 1.48 but not
properly in subsequent versions. Essentially, I'm displaying an ImageCanvas inside a JPanel, and the image data is generated programatically. The minimal example code I've got has a slider that varies the size of the generated image. It starts at some default size. Now, here's where the behaviour changes: In 1.48, as expected the generated image displays at the standard resolution/zoom level (i.e. 1 pixel to 1 pixel), and so when I make the image larger, the displayed area gets larger, and always contains the complete image. In 1.49 and up when I alter the size of the underlying ImageProcess to LESS than the original size, the complete image is displayed at a zoom level of 1. If, however I make the image LARGER than the original size, the displayed area on the screen grows to match (i.e. it's the same number of screen pixels in size as the image), but the image is zoomed in order to make the number of image pixels displayed the same number as the original size of the image. If that's not entirely clear, I've got links below to the Java source, the complete source and the JAR file: Source code: http://www.edwardrosten.com/test_image.java Complete (source code, makefile, JAR file, plugins.config): http://www.edwardrosten.com/minimal.tar.gz I'm guessing that I'm doing something wrong with how I change bits of information after updating the image. In the source code there's a function makeimage() which returns FloatProcessor images of various sizes. Here's a sketch of the code extracted from the source file: class EControlPanel extends JFrame { private ImagePlus image; //Reconstructed image private ImageCanvas canvas; EControlPanel() { image = new ImagePlus(); image.setProcessor(makeimage()); canvas = new ImageCanvas(image); //More stuff to make the canvas actually display } public void update_canvas() { image.setProcessor(makeimage()); //Not 100% sure about why I need these or if I do image.updateImage(); image.updateAndRepaintWindow(); canvas.repaint(); //Update the canvas size and viewport to prevent funny things with zooming. canvas.setDrawingSize(image.getWidth(), image.getHeight()); canvas.setSourceRect(new Rectangle(image.getWidth(), image.getHeight())); //cargo cult: prod the GUI system to decide whether we need scroll bars or not pack(); validate(); } } My current hypothesis is that I'm setting things wrong in the update_canvas function. I've tried adding a setMagnification(1). That doesn't work: it displays as before but without the zoom, i.e. it just displays a chunk of the top-left corner of the image that's the same size as the original. Interestingly though, the canvas does actually increase in size, because once it gets large enough then scrollbars (which are in the complete source code) appear, Does anyone have any ideas on how to make the image display correctly? -Ed -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |