/** * Method to display pixel information for the passed x and y * * @param pictureX the x value in the picture * @param pictureY the y value in the picture */ private void displayPixelInformation(int pictureX, int pictureY) { // check that this x and y are in range if (isLocationInPicture(pictureX, pictureY)) { // save the current x and y index colIndex = pictureX; rowIndex = pictureY; // get the pixel at the x and y Pixel pixel = new Pixel(picture, colIndex, rowIndex); // set the values based on the pixel colValue.setText(Integer.toString(colIndex + numberBase)); rowValue.setText(Integer.toString(rowIndex + numberBase)); rValue.setText("R: " + pixel.getRed()); gValue.setText("G: " + pixel.getGreen()); bValue.setText("B: " + pixel.getBlue()); colorPanel.setBackground(new Color(pixel.getRed(), pixel.getGreen(), pixel.getBlue())); } else { clearInformation(); } // notify the image display of the current x and y imageDisplay.setCurrentX((int) (colIndex * zoomFactor)); imageDisplay.setCurrentY((int) (rowIndex * zoomFactor)); }
/** * 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 }