Java Code Examples for java.awt.MediaTracker#addImage()

The following examples show how to use java.awt.MediaTracker#addImage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JpegEncoder.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
public JpegEncoder(Image image, int quality, OutputStream out) {
	MediaTracker tracker = new MediaTracker(this);
	tracker.addImage(image, 0);
	try {
		tracker.waitForID(0);
	} catch (InterruptedException e) {
		// Got to do something?
	}
	/*
	 * Quality of the image. 0 to 100 and from bad image quality, high
	 * compression to good image quality low compression
	 */
	Quality = quality;

	/*
	 * Getting picture information It takes the Width, Height and RGB scans of
	 * the image.
	 */
	JpegObj = new JpegInfo(image);

	imageHeight = JpegObj.imageHeight;
	imageWidth = JpegObj.imageWidth;
	outStream = new BufferedOutputStream(out);
	dct = new DCT(Quality);
	Huf = new Huffman(imageWidth, imageHeight);
}
 
Example 2
Source File: MultiResolutionImageTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 3
Source File: PMUtil.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Ensures that Images is completely loaded
 */
public static boolean setImage(Image im, JComponent c) {
    boolean b = true;
    MediaTracker mt = new MediaTracker(c);
    mt.addImage(im, 0);
    try {
        mt.waitForID(0);
    } catch (InterruptedException e) {
        System.out.println("Error while image loading."); //$NON-NLS-1$
        b = false;
    }
    if (mt.isErrorID(0)) {
        System.out.println("Could Not load Image."); //$NON-NLS-1$
        b = false;
    }
    return b;
}
 
Example 4
Source File: ImageModeCanvas.java    From niftyeditor with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new form ImageModeCanvas
 */
public ImageModeCanvas(ImageModeModel model) {
    initComponents();
    this.model = model;
    MediaTracker tracker = new MediaTracker(this);
    this.image = Toolkit.getDefaultToolkit().createImage(this.model.getImage());
    tracker.addImage(image, 0);
    try {
        tracker.waitForID(0);
    } catch (InterruptedException ex) {
        Logger.getLogger(ImageModeCanvas.class.getName()).log(Level.SEVERE, null, ex);
    }
    this.painter = new ResizePainter((ResizeImageMode)model, image.getWidth(null), image.getHeight(null));
    this.addMouseListener(painter);
    this.addMouseMotionListener(painter);
}
 
Example 5
Source File: CommonAboutDialog.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the single title image in a threadsafe way.
 * 
 * @param frame - a <code>JFrame</code> object to instantiate the image.
 * @return the title <code>Image</code> common to all "about" dialogs.
 *         This value should <b>not</b> be <code>null</code>.
 */
private static synchronized Image getTitleImage(JFrame frame) {
    // Have we loaded our image yet?
    if (imgTitleImage == null) {
        // Nope. Load it.
        Image image = frame.getToolkit().getImage(
                new MegaMekFile(Configuration.miscImagesDir(), FILENAME_MEGAMEK_SPLASH2).toString()
        );
        MediaTracker tracker = new MediaTracker(frame);
        tracker.addImage(image, 0);
        try {
            tracker.waitForID(0);
            imgTitleImage = image;
        } catch (InterruptedException exp) {
            exp.printStackTrace();
        }
    } // End load-imgTitleImage

    return imgTitleImage;
}
 
Example 6
Source File: TilesetManager.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  Loads a preview image of the unit into the BufferedPanel.
 */
public Image loadPreviewImage(Entity entity, Image camo, int tint, Component bp) {
    Image base = mechTileset.imageFor(entity, boardview, -1);
    EntityImage entityImage = new EntityImage(base, tint, camo, bp);
    entityImage.loadFacings();
    Image preview = entityImage.getFacing(entity.getFacing());

    MediaTracker loadTracker = new MediaTracker(boardview);
    loadTracker.addImage(preview, 0);
    try {
        loadTracker.waitForID(0);
    } catch (InterruptedException e) {
        // should never come here

    }

    return preview;
}
 
Example 7
Source File: MultiResolutionImageTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
 
Example 8
Source File: MultiResolutionImageTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
 
Example 9
Source File: ReliefImageBreaker.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Asks the user to select an image and then it loads it up into an Image object and returns it to
 * the calling class.
 *
 * @return The loaded image.
 */
private Image loadImage() {
  log.info("Select the map");
  final String mapName =
      new FileOpen("Select The Map", mapFolderLocation, ".gif", ".png").getPathString();
  if (mapName != null) {
    final Image img = Toolkit.getDefaultToolkit().createImage(mapName);
    final MediaTracker tracker = new MediaTracker(new Panel());
    tracker.addImage(img, 1);
    try {
      tracker.waitForAll();
      return img;
    } catch (final InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
  return null;
}
 
Example 10
Source File: RuntimeBuiltinLeafInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        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_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
 
Example 11
Source File: Util.java    From beanshell with Apache License 2.0 6 votes vote down vote up
public static void startSplashScreen()
{
    int width=275,height=148;
    Window win=new Window( new Frame() );
    win.pack();
    BshCanvas can=new BshCanvas();
    can.setSize( width, height ); // why is this necessary?
    Toolkit tk=Toolkit.getDefaultToolkit();
    Dimension dim=tk.getScreenSize();
    win.setBounds(
        dim.width/2-width/2, dim.height/2-height/2, width, height );
    win.add("Center", can);
    Image img=tk.getImage(
        Interpreter.class.getResource("/bsh/util/lib/splash.gif") );
    MediaTracker mt=new MediaTracker(can);
    mt.addImage(img,0);
    try { mt.waitForAll(); } catch ( Exception e ) { }
    Graphics gr=can.getBufferedGraphics();
    gr.drawImage(img, 0, 0, can);
    win.setVisible(true);
    win.toFront();
    splashScreen = win;
}
 
Example 12
Source File: MultiResolutionImageTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
 
Example 13
Source File: JasperApp.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public void run() throws JRException
{
	long start = System.currentTimeMillis();
	//Preparing parameters
	Image image = Toolkit.getDefaultToolkit().createImage("dukesign.jpg");
	MediaTracker traker = new MediaTracker(new Panel());
	traker.addImage(image, 0);
	try
	{
		traker.waitForID(0);
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
	
	Map<String, Object> parameters = new HashMap<String, Object>();
	parameters.put("ReportTitle", "The First Jasper Report Ever");
	parameters.put("MaxOrderID", 10500);
	parameters.put("SummaryImage", image);
	
	JasperRunManager.runReportToPdfFile("build/reports/FirstJasper.jasper", parameters, getDemoHsqldbConnection());
	System.err.println("PDF running time : " + (System.currentTimeMillis() - start));
}
 
Example 14
Source File: GraphicUtils.java    From xyTalk-pc with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
    * Loading an image via a MediaTracker
    * 
    * @param image
    * @throws InterruptedException
    * @throws IOException
    */
   public static void load(Image image) throws InterruptedException,
    IOException {
MediaTracker tracker = new MediaTracker(new Label()); // any component
						      // will do
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorID(0))
    throw new IOException("error loading image");
   }
 
Example 15
Source File: HorizontalApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public void fill() throws JRException
{
	long start = System.currentTimeMillis();
	//Preparing parameters
	Image image = 
		Toolkit.getDefaultToolkit().createImage(
			JRLoader.loadBytesFromResource("dukesign.jpg")
			);
	MediaTracker traker = new MediaTracker(new Panel());
	traker.addImage(image, 0);
	try
	{
		traker.waitForID(0);
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
	
	Map<String, Object> parameters = new HashMap<String, Object>();
	parameters.put("ReportTitle", "The Horizontal Report");
	parameters.put("MaxOrderID", 10500);
	parameters.put("SummaryImage", image);
	
	JasperFillManager.fillReportToFile("build/reports/HorizontalReport.jasper", parameters, getDemoHsqldbConnection());
	System.err.println("Filling time : " + (System.currentTimeMillis() - start));
}
 
Example 16
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
public MainPanel() {
    // �p�l���̐����T�C�Y��ݒ�Apack()����Ƃ��ɕK�v
    setPreferredSize(new Dimension(WIDTH, HEIGHT));

    // �C���[�W��ǂݍ���
    image = Toolkit.getDefaultToolkit().getImage(
            getClass().getResource("image.gif"));

    // MediaTracker�ɓo�^
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(image, 0);
    // �C���[�W�ǂݍ��݊����܂őҋ@
    try {
        tracker.waitForID(0);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example 17
Source File: GoldToad.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �^�̉摜�����[�h����B
 * 
 * @param panel MainPanel�ւ̎Q�ƁB
 */
protected void loadImage(MainPanel panel) {
    MediaTracker tracker = new MediaTracker(panel);
    toadImage = Toolkit.getDefaultToolkit().getImage(
            getClass().getResource("gold_toad.gif"));
    tracker.addImage(toadImage, 0);
    try {
        tracker.waitForAll();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example 18
Source File: JasperApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public void fill() throws JRException
{
	long start = System.currentTimeMillis();
	//Preparing parameters
	Image image = 
		Toolkit.getDefaultToolkit().createImage(
			JRLoader.loadBytesFromResource("dukesign.jpg")
			);
	MediaTracker traker = new MediaTracker(new Panel());
	traker.addImage(image, 0);
	try
	{
		traker.waitForID(0);
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
	
	Map<String, Object> parameters = new HashMap<String, Object>();
	parameters.put("ReportTitle", "The First Jasper Report Ever");
	parameters.put("MaxOrderID", 10500);
	parameters.put("SummaryImage", image);
	
	JasperFillManager.fillReportToFile("build/reports/FirstJasper.jasper", parameters, getDemoHsqldbConnection());
	System.err.println("Filling time : " + (System.currentTimeMillis() - start));
}
 
Example 19
Source File: MultiResolutionImageTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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");
    }
}
 
Example 20
Source File: MultiResolutionImageTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
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");
    }
}