Search in sources :

Example 11 with MediaTracker

use of java.awt.MediaTracker in project cxf by apache.

the class SwAOutInterceptor method convertToBufferedImage.

private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }
    // Wait until the image is completely loaded
    MediaTracker tracker = new MediaTracker(new Component() {

        private static final long serialVersionUID = 6412221228374321325L;
    });
    tracker.addImage(image, 0);
    try {
        tracker.waitForAll();
    } catch (InterruptedException e) {
        throw new Fault(e);
    }
    // Create a BufferedImage so we can write it out later
    BufferedImage bufImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    Graphics g = bufImage.createGraphics();
    g.drawImage(image, 0, 0, null);
    return bufImage;
}
Also used : Graphics(java.awt.Graphics) MediaTracker(java.awt.MediaTracker) Fault(org.apache.cxf.interceptor.Fault) Component(java.awt.Component) BufferedImage(java.awt.image.BufferedImage)

Example 12 with MediaTracker

use of java.awt.MediaTracker in project cxf by apache.

the class ImageHelper method convertToBufferedImage.

private static BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }
    /*not sure how this is used*/
    MediaTracker tracker = new MediaTracker(null);
    tracker.addImage(image, 0);
    try {
        tracker.waitForAll();
    } catch (InterruptedException e) {
        throw new IOException(e.getMessage());
    }
    BufferedImage bufImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics g = bufImage.createGraphics();
    g.drawImage(image, 0, 0, null);
    return bufImage;
}
Also used : Graphics(java.awt.Graphics) MediaTracker(java.awt.MediaTracker) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Example 13 with MediaTracker

use of java.awt.MediaTracker in project adempiere by adempiere.

the class MImage method getImage.

/**
	 * 	Get Image
	 *	@return image or null
	 */
public Image getImage() {
    if (m_image != null)
        return m_image;
    //	Via byte array
    byte[] data = getBinaryData();
    if (data != null && data.length > 0) {
        try {
            BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(data));
            m_image = bufferedImage;
            return m_image;
        } catch (IOException e) {
            log.log(Level.WARNING, "(byteArray)", e);
            return null;
        }
    /*try
			{
				Toolkit tk = Toolkit.getDefaultToolkit();
				m_image = tk.createImage(data);
				MediaTracker mediaTracker = new MediaTracker(new Container());
                mediaTracker.addImage(m_image, 0);
                mediaTracker.waitForID(0);
				return m_image;
			}
			catch (Exception e)
			{
				log.log(Level.WARNING, "(byteArray)", e);
				return null;
			}*/
    }
    //	Via URL
    URL url = getURL();
    if (url == null)
        return null;
    try {
        Toolkit tk = Toolkit.getDefaultToolkit();
        m_image = tk.getImage(url);
        MediaTracker mediaTracker = new MediaTracker(new Container());
        mediaTracker.addImage(m_image, 0);
        mediaTracker.waitForID(0);
        return m_image;
    } catch (Exception e) {
        log.log(Level.WARNING, "(URL)", e);
    }
    return null;
}
Also used : MediaTracker(java.awt.MediaTracker) Container(java.awt.Container) ByteArrayInputStream(java.io.ByteArrayInputStream) Toolkit(java.awt.Toolkit) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) URL(java.net.URL) IOException(java.io.IOException)

Example 14 with MediaTracker

use of java.awt.MediaTracker in project jdk8u_jdk by JetBrains.

the class MultiResolutionImageTest method testToolkitMultiResolutionImage.

static void testToolkitMultiResolutionImage(Image image, boolean enableImageScaling) throws Exception {
    MediaTracker tracker = new MediaTracker(new JPanel());
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    if (tracker.isErrorAny()) {
        throw new RuntimeException("Error during image loading");
    }
    final BufferedImage bufferedImage1x = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
    Graphics2D g1x = (Graphics2D) bufferedImage1x.getGraphics();
    setImageScalingHint(g1x, false);
    g1x.drawImage(image, 0, 0, null);
    checkColor(bufferedImage1x.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false);
    Image resolutionVariant = ((MultiResolutionImage) image).getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT);
    if (resolutionVariant == null) {
        throw new RuntimeException("Resolution variant is null");
    }
    MediaTracker tracker2x = new MediaTracker(new JPanel());
    tracker2x.addImage(resolutionVariant, 0);
    tracker2x.waitForID(0);
    if (tracker2x.isErrorAny()) {
        throw new RuntimeException("Error during scalable image loading");
    }
    final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics();
    setImageScalingHint(g2x, enableImageScaling);
    g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null);
    checkColor(bufferedImage2x.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling);
    if (!(image instanceof MultiResolutionImage)) {
        throw new RuntimeException("Not a MultiResolutionImage");
    }
    MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;
    Image image1x = multiResolutionImage.getResolutionVariant(IMAGE_WIDTH, IMAGE_HEIGHT);
    Image image2x = multiResolutionImage.getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT);
    if (image1x.getWidth(null) * 2 != image2x.getWidth(null) || image1x.getHeight(null) * 2 != image2x.getHeight(null)) {
        throw new RuntimeException("Wrong resolution variant size");
    }
}
Also used : JPanel(javax.swing.JPanel) MediaTracker(java.awt.MediaTracker) MultiResolutionImage(java.awt.image.MultiResolutionImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) MultiResolutionImage(java.awt.image.MultiResolutionImage)

Example 15 with MediaTracker

use of java.awt.MediaTracker in project jdk8u_jdk by JetBrains.

the class MultiResolutionImageTest method testToolkitMultiResolutionImageLoad.

static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
    MediaTracker tracker = new MediaTracker(new JPanel());
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    if (tracker.isErrorAny()) {
        throw new RuntimeException("Error during image loading");
    }
    tracker.removeImage(image, 0);
    testImageLoaded(image);
    int w = image.getWidth(null);
    int h = image.getHeight(null);
    Image resolutionVariant = ((MultiResolutionImage) image).getResolutionVariant(2 * w, 2 * h);
    if (image == resolutionVariant) {
        throw new RuntimeException("Resolution variant is not loaded");
    }
    testImageLoaded(resolutionVariant);
}
Also used : JPanel(javax.swing.JPanel) MediaTracker(java.awt.MediaTracker) MultiResolutionImage(java.awt.image.MultiResolutionImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) MultiResolutionImage(java.awt.image.MultiResolutionImage)

Aggregations

MediaTracker (java.awt.MediaTracker)30 Image (java.awt.Image)17 BufferedImage (java.awt.image.BufferedImage)16 Graphics (java.awt.Graphics)7 IOException (java.io.IOException)7 Toolkit (java.awt.Toolkit)5 Container (java.awt.Container)4 JLabel (javax.swing.JLabel)4 Component (java.awt.Component)3 MultiResolutionImage (java.awt.image.MultiResolutionImage)3 File (java.io.File)3 URL (java.net.URL)3 JPanel (javax.swing.JPanel)3 SimpleImage (org.jwildfire.image.SimpleImage)3 Dimension (java.awt.Dimension)2 Graphics2D (java.awt.Graphics2D)2 Panel (java.awt.Panel)2 PixelGrabber (java.awt.image.PixelGrabber)2 BarCodeBuilder (com.aspose.barcode.BarCodeBuilder)1 Frame (java.awt.Frame)1