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;
}
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;
}
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;
}
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");
}
}
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);
}
Aggregations