/** * Returns a new BufferedImage that represents a subregion of the given * BufferedImage. (Note that this method does not use * BufferedImage.getSubimage(), which will defeat image acceleration * strategies on later JDKs.) */ private BufferedImage getSubImage(BufferedImage img, int x, int y, int w, int h) { BufferedImage ret = GraphicsUtilities.createCompatibleTranslucentImage(w, h); Graphics2D g2 = ret.createGraphics(); try { g2.drawImage(img, 0, 0, w, h, x, y, x+w, y+h, null); } finally { g2.dispose(); } return ret; }
/** * {@inheritDoc} */ @Override public ColorModel getColorModel() { if (saved == null) { return GraphicsUtilities.createCompatibleImage(1, 1).getColorModel(); } return saved.getColorModel(); }
@Override public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { //log.fine("doing get trans data: " + flavor); if(flavor == DataFlavor.imageFlavor) { return img; } if(flavor == DataFlavor.javaFileListFlavor) { if(files == null) { files = new ArrayList<File>(); File file = File.createTempFile(exportName,"."+exportFormat); //log.fine("writing to: " + file); ImageIO.write(GraphicsUtilities.convertToBufferedImage(img),exportFormat,file); files.add(file); } //log.fine("returning: " + files); return files; } return null; } }
/** * <p>Returns a new opaque compatible image of the specified width and * height. That is, the returned <code>BufferedImage</code> is compatible with * the graphics hardware. If the method is called in a headless * environment, then the returned BufferedImage will be compatible with * the source image.</p> * * @see #createCompatibleImage(java.awt.image.BufferedImage) * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int) * @see #createCompatibleTranslucentImage(int, int) * @see #loadCompatibleImage(java.net.URL) * @see #toCompatibleImage(java.awt.image.BufferedImage) * @param width the width of the new image * @param height the height of the new image * @return a new opaque compatible <code>BufferedImage</code> of the * specified width and height */ public static BufferedImage createCompatibleImage(int width, int height) { return isHeadless() ? new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB) : getGraphicsConfiguration().createCompatibleImage(width, height); }
@Test public void testGreenOverHorizontal() throws Exception { expected = loadCompatibleImage(BlendCompositeTest.class.getResourceAsStream("green-over-horizontal.gif")); BufferedImage green = GraphicsUtilities.createCompatibleImage(VERTICAL_IMAGE); Graphics2D g = green.createGraphics(); try { g.setColor(Color.GREEN); g.fillRect(0, 0, green.getWidth(), green.getHeight()); } finally { g.dispose(); } blend(HORIZONTAL_IMAGE, BlendComposite.Green, green); assertArrayEquals(getPixels(expected, 0, 0, expected.getWidth(), expected.getHeight(), null), getPixels(actual, 0, 0, actual.getWidth(), actual.getHeight(), null)); }
@Test public void testDarkenVerticalOverHorizontal() throws Exception { expected = loadCompatibleImage(BlendCompositeTest.class.getResourceAsStream("darken.gif")); blend(HORIZONTAL_IMAGE, BlendComposite.Darken, VERTICAL_IMAGE); assertArrayEquals(getPixels(expected, 0, 0, expected.getWidth(), expected.getHeight(), null), getPixels(actual, 0, 0, actual.getWidth(), actual.getHeight(), null)); }
@Test public void testClear() { BufferedImage img = GraphicsUtilities.createCompatibleImage(1, 1); GraphicsUtilities.clear(img); assertThat(GraphicsUtilities.getPixels(img, 0, 0, 1, 1, null)[0], is(0)); } }
/** * <p>Returns a new compatible image from a URL. The image is loaded from the * specified location and then turned, if necessary into a compatible * image.</p> * * @see #createCompatibleImage(java.awt.image.BufferedImage) * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int) * @see #createCompatibleImage(int, int) * @see #createCompatibleTranslucentImage(int, int) * @see #toCompatibleImage(java.awt.image.BufferedImage) * @param resource the URL of the picture to load as a compatible image * @return a new translucent compatible <code>BufferedImage</code> of the * specified width and height * @throws java.io.IOException if the image cannot be read or loaded */ public static BufferedImage loadCompatibleImage(URL resource) throws IOException { BufferedImage image = ImageIO.read(resource); return toCompatibleImage(image); }
GraphicsUtilities.tileStretchPaint(g, this, colorwell, ins);
/** * <p>Returns a new opaque compatible image of the specified width and * height. That is, the returned <code>BufferedImage</code> is compatible with * the graphics hardware. If the method is called in a headless * environment, then the returned BufferedImage will be compatible with * the source image.</p> * * @see #createCompatibleImage(java.awt.image.BufferedImage) * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int) * @see #createCompatibleTranslucentImage(int, int) * @see #loadCompatibleImage(java.net.URL) * @see #toCompatibleImage(java.awt.image.BufferedImage) * @param width the width of the new image * @param height the height of the new image * @return a new opaque compatible <code>BufferedImage</code> of the * specified width and height */ public static BufferedImage createCompatibleImage(int width, int height) { return isHeadless() ? new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB) : getGraphicsConfiguration().createCompatibleImage(width, height); }
@Test public void testRedOverHorizontal() throws Exception { expected = loadCompatibleImage(BlendCompositeTest.class.getResourceAsStream("red-over-horizontal.gif")); BufferedImage red = GraphicsUtilities.createCompatibleImage(VERTICAL_IMAGE); Graphics2D g = red.createGraphics(); try { g.setColor(Color.RED); g.fillRect(0, 0, red.getWidth(), red.getHeight()); } finally { g.dispose(); } blend(HORIZONTAL_IMAGE, BlendComposite.Red, red); assertArrayEquals(getPixels(expected, 0, 0, expected.getWidth(), expected.getHeight(), null), getPixels(actual, 0, 0, actual.getWidth(), actual.getHeight(), null)); }
@Test public void testSoftDodgeHorizontalOverVertical() throws Exception { expected = loadCompatibleImage(BlendCompositeTest.class.getResourceAsStream("soft-burn-voh.gif")); blend(VERTICAL_IMAGE, BlendComposite.SoftDodge, HORIZONTAL_IMAGE); assertArrayEquals(getPixels(expected, 0, 0, expected.getWidth(), expected.getHeight(), null), getPixels(actual, 0, 0, actual.getWidth(), actual.getHeight(), null)); }
/** * <p>Returns a new compatible image from a URL. The image is loaded from the * specified location and then turned, if necessary into a compatible * image.</p> * * @see #createCompatibleImage(java.awt.image.BufferedImage) * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int) * @see #createCompatibleImage(int, int) * @see #createCompatibleTranslucentImage(int, int) * @see #toCompatibleImage(java.awt.image.BufferedImage) * @param resource the URL of the picture to load as a compatible image * @return a new translucent compatible <code>BufferedImage</code> of the * specified width and height * @throws java.io.IOException if the image cannot be read or loaded */ public static BufferedImage loadCompatibleImage(URL resource) throws IOException { BufferedImage image = ImageIO.read(resource); return toCompatibleImage(image); }
GraphicsUtilities.tileStretchPaint(g, this, colorwell, ins);
private BufferedImage getClipImage(final Rectangle effectBounds) { // set up a temp buffer if(_clipImage == null || _clipImage.getWidth() != effectBounds.width || _clipImage.getHeight() != effectBounds.height) { _clipImage = createCompatibleTranslucentImage(effectBounds.width, effectBounds.height); } _clipImage.getGraphics().clearRect(0,0,_clipImage.getWidth(), _clipImage.getHeight()); return _clipImage; }
/** * {@inheritDoc} */ @Override public ColorModel getColorModel() { if (saved == null) { return GraphicsUtilities.createCompatibleImage(1, 1).getColorModel(); } return saved.getColorModel(); }
/** * <p>Returns a new opaque compatible image of the specified width and * height. That is, the returned <code>BufferedImage</code> is compatible with * the graphics hardware. If the method is called in a headless * environment, then the returned BufferedImage will be compatible with * the source image.</p> * * @see #createCompatibleImage(java.awt.image.BufferedImage) * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int) * @see #createCompatibleTranslucentImage(int, int) * @see #loadCompatibleImage(java.net.URL) * @see #toCompatibleImage(java.awt.image.BufferedImage) * @param width the width of the new image * @param height the height of the new image * @return a new opaque compatible <code>BufferedImage</code> of the * specified width and height */ public static BufferedImage createCompatibleImage(int width, int height) { return isHeadless() ? new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB) : getGraphicsConfiguration().createCompatibleImage(width, height); }
@Test public void testBlueOverHorizontal() throws Exception { expected = loadCompatibleImage(BlendCompositeTest.class.getResourceAsStream("blue-over-horizontal.gif")); BufferedImage blue = GraphicsUtilities.createCompatibleImage(VERTICAL_IMAGE); Graphics2D g = blue.createGraphics(); try { g.setColor(Color.BLUE); g.fillRect(0, 0, blue.getWidth(), blue.getHeight()); } finally { g.dispose(); } blend(HORIZONTAL_IMAGE, BlendComposite.Blue, blue); assertArrayEquals(getPixels(expected, 0, 0, expected.getWidth(), expected.getHeight(), null), getPixels(actual, 0, 0, actual.getWidth(), actual.getHeight(), null)); } }
@Test public void testAddVerticalOverHorizontal() throws Exception { expected = loadCompatibleImage(BlendCompositeTest.class.getResourceAsStream("add.gif")); blend(HORIZONTAL_IMAGE, BlendComposite.Add, VERTICAL_IMAGE); assertArrayEquals(getPixels(expected, 0, 0, expected.getWidth(), expected.getHeight(), null), getPixels(actual, 0, 0, actual.getWidth(), actual.getHeight(), null)); }
/** * <p>Returns a new compatible image from a URL. The image is loaded from the * specified location and then turned, if necessary into a compatible * image.</p> * * @see #createCompatibleImage(java.awt.image.BufferedImage) * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int) * @see #createCompatibleImage(int, int) * @see #createCompatibleTranslucentImage(int, int) * @see #toCompatibleImage(java.awt.image.BufferedImage) * @param resource the URL of the picture to load as a compatible image * @return a new translucent compatible <code>BufferedImage</code> of the * specified width and height * @throws java.io.IOException if the image cannot be read or loaded */ public static BufferedImage loadCompatibleImage(URL resource) throws IOException { BufferedImage image = ImageIO.read(resource); return toCompatibleImage(image); }