@Override public void paint(Graphics g){ super.paint(g); // Have the extending class draw on an image so that it can be resized as needed Image bufferImage = createImage(DRAW_WIDTH, DRAW_HEIGHT); // Give control to visualization to draw on buffer paintVisualization((Graphics2D)bufferImage.getGraphics()); int width = getWidth(); int height = getHeight(); // Scale and resize the image ReplicateScaleFilter scale = new ReplicateScaleFilter(width, height); FilteredImageSource fis = new FilteredImageSource(bufferImage.getSource(), scale); Image croppedImage = createImage(fis); g.drawImage(croppedImage, 0, 0, null); Toolkit.getDefaultToolkit().sync(); }
/** * Scales an image to the specified width and height. This should also * be used to implement * {@link Toolkit#prepareImage(Image, int, int, ImageObserver)}. * This uses {@link Toolkit#createImage(ImageProducer)} to create the actual * image. * * @param image the image to prepare * @param w the width * @param h the height * * @return the scaled image */ public static Image prepareImage(Image image, int w, int h) { // Try to find cached scaled image. HashMap<Dimension,Image> scaledTable = imageCache.get(image); Dimension size = new Dimension(w, h); Image scaled = null; if (scaledTable != null) { scaled = scaledTable.get(size); } if (scaled == null) { // No cached scaled image. Start scaling image now. ImageProducer source = image.getSource(); ReplicateScaleFilter scaler = new ReplicateScaleFilter(w, h); FilteredImageSource filteredSource = new FilteredImageSource(source, scaler); // Ideally, this should asynchronously scale the image. Image scaledImage = Toolkit.getDefaultToolkit().createImage(filteredSource); scaled = scaledImage; // Put scaled image in cache. if (scaledTable == null) { scaledTable = new HashMap<Dimension,Image>(); imageCache.put(image, scaledTable); } scaledTable.put(size, scaledImage); } return scaled; }
public static BufferedImage scaleImage(Image sourceImage, int width, int height) { if (sourceImage == null) return null; ImageFilter filter = new ReplicateScaleFilter(width,height); ImageProducer producer = new FilteredImageSource(sourceImage.getSource(),filter); Image resizedImage = Toolkit.getDefaultToolkit().createImage(producer); return toBufferedImage(resizedImage); }
private BufferedImage scaleImage(Image sourceImage, int width, int height, int typeRGB) { ImageFilter filter = new ReplicateScaleFilter(width, height); ImageProducer producer = new FilteredImageSource(sourceImage .getSource(), filter); Image resizedImage = Toolkit.getDefaultToolkit().createImage(producer); return this.toBufferedImage(resizedImage, typeRGB); }
/** Zoom the image, preparing for new display. */ protected void zoomSet(float zoom) { this.zoom = zoom; if (spectrogram != null) { int width = spectrogram.getWidth(); int height = spectrogram.getHeight(); ImageFilter scaleFilter = new ReplicateScaleFilter((int) (zoom * width), height); scaledSpectrogram = createImage(new FilteredImageSource(spectrogram.getSource(), scaleFilter)); repaint(); } }
public static void main(String args[]) { new ReplicateScaleFilter(100, 100).clone(); }
private static BufferedImage scaleCompanyImage(Image sourceImage, int width, int height) { ImageFilter filter = new ReplicateScaleFilter(width, height); ImageProducer producer = new FilteredImageSource(sourceImage.getSource(), filter); Image rImage = Toolkit.getDefaultToolkit().createImage(producer); return toBufferedCompanyImage(rImage); }