/** Create and initialize the scrolling image */ private void createAndInitScrollingImage() { scrollPane = new JScrollPane(); BufferedImage bimg = picture.getBufferedImage(); imageDisplay = new ImageDisplay(bimg); imageDisplay.addMouseMotionListener(this); imageDisplay.addMouseListener(this); imageDisplay.setToolTipText("Click a mouse button on a pixel to see the pixel information"); scrollPane.setViewportView(imageDisplay); pictureFrame.getContentPane().add(scrollPane, BorderLayout.CENTER); }
/** * Zooms in the on picture by scaling the image. It is extremely memory intensive. * * @param factor the amount to zoom by */ public void zoom(double factor) { // save the current zoom factor zoomFactor = factor; // calculate the new width and height and get an image that size int width = (int) (picture.getWidth() * zoomFactor); int height = (int) (picture.getHeight() * zoomFactor); BufferedImage bimg = picture.getBufferedImage(); // set the scroll image icon to the new image imageDisplay.setImage(bimg.getScaledInstance(width, height, Image.SCALE_DEFAULT)); imageDisplay.setCurrentX((int) (colIndex * zoomFactor)); imageDisplay.setCurrentY((int) (rowIndex * zoomFactor)); imageDisplay.revalidate(); checkScroll(); // check if need to reposition scroll }