Here you can find the source of optimizeForGraphicsHardwareIfRequired(BufferedImage image)
Parameter | Description |
---|---|
image | The image to optimize. |
public static BufferedImage optimizeForGraphicsHardwareIfRequired(BufferedImage image)
//package com.java2s; import java.awt.*; public class Main { /**//from w w w . j ava 2s .c om * Converts an image to an optimized version for the default screen.<br> * The optimized image should draw faster. Only creates a new image if * the passed image is not already optimized. * @param image The image to optimize. * @return Returns the optimized image. */ public static BufferedImage optimizeForGraphicsHardwareIfRequired(BufferedImage image) { try { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); // return passed image if it already is optimized if (image.getColorModel().equals(gc.getColorModel())) { return image; } // create an empty optimized BufferedImage int w = image.getWidth(); int h = image.getHeight(); // strange things happen on Linux and Windows on some systems when // monitors are set to 16 bit. boolean bit16 = gc.getColorModel().getPixelSize() < 24; final int transp; if (bit16) { transp = Transparency.TRANSLUCENT; } else { transp = image.getColorModel().getTransparency(); } BufferedImage optimized = gc.createCompatibleImage(w, h, transp); // draw the passed image into the optimized image optimized.getGraphics().drawImage(image, 0, 0, null); return optimized; } catch (Exception e) { // return the original image if an exception occured. return image; } } }