Java GraphicsConfiguration .createCompatibleVolatileImage (int width, int height)

Syntax

GraphicsConfiguration.createCompatibleVolatileImage(int width, int height) has the following syntax.

public VolatileImage createCompatibleVolatileImage(int width,      int height)

Example

In the following code shows how to use GraphicsConfiguration.createCompatibleVolatileImage(int width, int height) method.


import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;
/* w  w  w  .  j  a  va 2  s  .co  m*/
import javax.swing.ImageIcon;

public class Main {
    public static BufferedImage toBufferedImage(Image image) {
        if (image instanceof BufferedImage) {
            return (BufferedImage)image;
        }
    
        // This code ensures that all the pixels in the image are loaded
        image = new ImageIcon(image).getImage();
        // Create a buffered image with a format that's compatible with the screen
        BufferedImage bimage = null;
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        try {
            GraphicsDevice gs = ge.getDefaultScreenDevice();
            GraphicsConfiguration gc = gs.getDefaultConfiguration();
            VolatileImage vbimage = gc.createCompatibleVolatileImage(200,200);
        } catch (HeadlessException e) {
            // The system does not have a screen
        }   
        return bimage;
    }
} 




















Home »
  Java Tutorial »
    java.awt »




BasicStroke
BorderLayout
CardLayout
Color
Cursor
Desktop
DesktopManager
DisplayMode
EventQueue
FlowLayout
FocusTraversalPolicy
Font
FontMetrics
GradientPaint
Graphics
Graphics2D
GraphicsConfiguration
GraphicsDevice
GraphicsEnvironment
GridBagConstraints
GridBagLayout
GridLayout
Image
ItemSelectable
KeyboardFocusManager
LayoutManager
LayoutManager2
Point
Rectangle
Robot
Shape
SplashScreen
SystemColor
SystemTray
TexturePaint
TrayIcon
Toolkit
Transparency