Example usage for java.awt.image ImageProducer startProduction

List of usage examples for java.awt.image ImageProducer startProduction

Introduction

In this page you can find the example usage for java.awt.image ImageProducer startProduction.

Prototype

public void startProduction(ImageConsumer ic);

Source Link

Document

Registers the specified ImageConsumer object as a consumer and starts an immediate reconstruction of the image data which will then be delivered to this consumer and any other consumer which might have already been registered with the producer.

Usage

From source file:org.eclipse.wb.internal.swing.utils.SwingImageUtils.java

/**
 * Converts AWT image into SWT one. Yours, C.O. ;-)
 *//* w w  w. j av a  2 s .c o m*/
public static Image convertImage_AWT_to_SWT(final java.awt.Image image) throws Exception {
    return SwingUtils.runObjectLaterAndWait(new RunnableObjectEx<Image>() {
        public Image runObject() throws Exception {
            BufferedImage bufferedImage = (BufferedImage) image;
            int imageWidth = bufferedImage.getWidth();
            int imageHeight = bufferedImage.getHeight();
            Image swtImage = new Image(null, imageWidth, imageHeight);
            final ImageData swtImageData = swtImage.getImageData();
            try {
                ImageProducer source = image.getSource();
                source.startProduction(new AwtToSwtImageConverter(bufferedImage, swtImageData));
                return new Image(null, swtImageData);
            } catch (Throwable e) {
                // fallback to ImageIO.
                return ImageUtils.convertToSWT(image);
            } finally {
                swtImage.dispose();
            }
        }
    });
}