当前位置: 首页>>代码示例>>Java>>正文


Java MediaTracker.isErrorAny方法代码示例

本文整理汇总了Java中java.awt.MediaTracker.isErrorAny方法的典型用法代码示例。如果您正苦于以下问题:Java MediaTracker.isErrorAny方法的具体用法?Java MediaTracker.isErrorAny怎么用?Java MediaTracker.isErrorAny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.MediaTracker的用法示例。


在下文中一共展示了MediaTracker.isErrorAny方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testToolkitMultiResolutionImageLoad

import java.awt.MediaTracker; //导入方法依赖的package包/类
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);
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:MultiResolutionImageTest.java

示例2: testToolkitMultiResolutionImageLoad

import java.awt.MediaTracker; //导入方法依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:MultiResolutionImageTest.java

示例3: getImage

import java.awt.MediaTracker; //导入方法依赖的package包/类
/**
 * Get Image from path provided
 *
 * @param url location of the image
 * @return the Image file
 */
public Image getImage(URL url) {
	try {
		MediaTracker tracker = new MediaTracker(this);
		
		Image image = super.getImage(url);

		// wait for image to load
		tracker.addImage(image, 0);
        tracker.waitForAll();

        // if no errors return image
        if (!tracker.isErrorAny()) {
        	return image;
        }
	} catch (Exception e) {
		/* */
	}
	
	return null;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:27,代码来源:AppletLoader.java

示例4: loadImage

import java.awt.MediaTracker; //导入方法依赖的package包/类
public static Image loadImage(String filename, Component watcher, URL url) {
    Image image = null;

    if (url == null) {
        System.err.println("loadImage() could not find \"" + filename + "\"");
    } else {
        image = watcher.getToolkit().getImage(url);
        if (image == null) {
            System.err.println("loadImage() getImage() failed for \"" + filename + "\"");
        } else {
            MediaTracker tracker = new MediaTracker(watcher);

            try {
                tracker.addImage(image, 0);
                tracker.waitForID(0);
            } catch (InterruptedException e) {
                System.err.println("loadImage(): " + e);
            } finally {
                boolean isError = tracker.isErrorAny();
                if (isError) {
                    System.err.println("loadImage() failed to load \"" + filename + "\"");
                    int flags = tracker.statusAll(true);

                    boolean loading = 0 != (flags & MediaTracker.LOADING);
                    boolean aborted = 0 != (flags & MediaTracker.ABORTED);
                    boolean errored = 0 != (flags & MediaTracker.ERRORED);
                    boolean complete = 0 != (flags & MediaTracker.COMPLETE);
                    System.err.println("loading: " + loading);
                    System.err.println("aborted: " + aborted);
                    System.err.println("errored: " + errored);
                    System.err.println("complete: " + complete);
                }
            }
        }
    }

    return image;
}
 
开发者ID:addertheblack,项目名称:myster,代码行数:39,代码来源:Util.java

示例5: loadImage

import java.awt.MediaTracker; //导入方法依赖的package包/类
public static edu.cmu.hcii.citrus.views.Image loadImage(URL path) {
	
	if(path.toString().endsWith("jpg") || path.toString().endsWith("png") || path.toString().endsWith("gif")) {
		java.awt.Image newImage = Toolkit.getDefaultToolkit().createImage(path);
		MediaTracker tracker = new MediaTracker(c);
		tracker.addImage(newImage, 0);
		try { tracker.waitForAll(); } catch(InterruptedException ex) {}
		if(newImage != null || !tracker.isErrorAny()) return new Image(newImage);
		else System.err.println("Couldn't load " + path);
		return null;
	} else return null;
	
}
 
开发者ID:andyjko,项目名称:citrus-barista,代码行数:14,代码来源:Images.java

示例6: testToolkitMultiResolutionImage

import java.awt.MediaTracker; //导入方法依赖的package包/类
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");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:53,代码来源:MultiResolutionImageTest.java

示例7: testToolkitMultiResolutionImage

import java.awt.MediaTracker; //导入方法依赖的package包/类
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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:59,代码来源:MultiResolutionImageTest.java

示例8: paint

import java.awt.MediaTracker; //导入方法依赖的package包/类
public void paint(Graphics2D g) {
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                       RenderingHints.VALUE_ANTIALIAS_ON);
    //
    // Load Image
    //
    Image image = Toolkit.getDefaultToolkit().createImage("test-resources/org/apache/batik/svggen/resources/vangogh.png");
    MediaTracker tracker = new MediaTracker(new Button(""));
    tracker.addImage(image, 0);
    try{
        tracker.waitForAll();
    }catch(InterruptedException e){
        tracker.removeImage(image);
        image = null;
    }finally {
        if(image != null)
            tracker.removeImage(image);
        if(tracker.isErrorAny())
            image = null;
        if(image != null){
            if(image.getWidth(null)<0 ||
               image.getHeight(null)<0)
                image = null;
        }
    }

    if(image == null){
        throw new Error("Could not load image");
    }

    BufferedImage bi = new BufferedImage(image.getWidth(null),
                                         image.getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics2D ig = bi.createGraphics();
    ig.drawImage(image, 0, 0, null);

    byte[] lookup = new byte[256];
    for(int i=0; i<256; i++)
        lookup[i] = (byte)(255 - i);

    LookupTable table = new ByteLookupTable(0, lookup);
    java.awt.image.LookupOp inverter = new java.awt.image.LookupOp(table, null);

    // Simply paint the image without and with the lookup filter
    g.setPaint(Color.black);
    g.drawString("Normal / Inverted", 10, 20);
    g.drawImage(image, 10, 30, null);
    g.drawImage(bi, inverter, 10 + bi.getWidth() + 10, 30);
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:49,代码来源:Lookup.java

示例9: paint

import java.awt.MediaTracker; //导入方法依赖的package包/类
public void paint(Graphics2D g) {
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                       RenderingHints.VALUE_ANTIALIAS_ON);
    //
    // Load Image
    //
    Image image = Toolkit.getDefaultToolkit().createImage("test-resources/org/apache/batik/svggen/resources/vangogh.jpg");
    MediaTracker tracker = new MediaTracker(new Button(""));
    tracker.addImage(image, 0);
    try{
        tracker.waitForAll();
    }catch(InterruptedException e){
        tracker.removeImage(image);
        image = null;
    }finally {
        if(image != null)
            tracker.removeImage(image);
        if(tracker.isErrorAny())
            image = null;
        if(image != null){
            if(image.getWidth(null)<0 ||
               image.getHeight(null)<0)
                image = null;
        }
    }

    if(image == null){
        throw new Error("Could not load image");
    }

    BufferedImage bi = new BufferedImage(image.getWidth(null),
                                         image.getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics2D ig = bi.createGraphics();
    ig.drawImage(image, 0, 0, null);

    java.awt.image.RescaleOp brighten = new java.awt.image.RescaleOp(1.5f, 0, null);
    java.awt.image.RescaleOp darken = new java.awt.image.RescaleOp(.6f, 0, null);

    // Simply paint the image without and with rescale filters
    g.setPaint(Color.black);
    g.drawString("Brighter / Normal / Darker", 10, 20);
    g.drawImage(bi, brighten, 10, 30);
    g.drawImage(image, 10 + bi.getWidth() + 10, 30, null);
    g.drawImage(bi, darken, 10 + 2*(bi.getWidth() + 10), 30);

    g.translate(0, bi.getHeight() + 30 + 20);
    g.drawString("Rescale Red / Green / Blue", 10, 20);
    java.awt.image.RescaleOp redStress = new java.awt.image.RescaleOp(new float[]{ 2.0f, 1.0f, 1.0f },
                                        new float[]{ 0, 0, 0 }, null);
    java.awt.image.RescaleOp greenStress = new java.awt.image.RescaleOp(new float[]{ 1.0f, 2.0f, 1.0f },
                                          new float[]{ 0, 0, 0 }, null);
    java.awt.image.RescaleOp blueStress = new java.awt.image.RescaleOp(new float[]{ 1.0f, 1.0f, 2.0f },
                                         new float[]{ 0, 0, 0 }, null);

    g.drawImage(bi, redStress, 10, 30);
    g.drawImage(bi, greenStress, 10 + bi.getWidth() + 10, 30);
    g.drawImage(bi, blueStress, 10 + 2*(bi.getWidth() + 10), 30);
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:59,代码来源:Rescale.java

示例10: createImage

import java.awt.MediaTracker; //导入方法依赖的package包/类
public BufferedImage createImage(String file) {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        URL u = ImageManager.class.getResource(file);
        if (u == null) {
            System.out.println("Could not find resource " + file);
            return null;
        }
        Image img = toolkit.createImage(u);
        if (img == null) {
            System.out.println("Couldn't load image " + file);
            return null;
        }


        MediaTracker mt = new MediaTracker(comp);
        try {
            mt.addImage(img, 0);
            mt.waitForAll();
        } catch (Exception e) {
            System.out.println("Couldn't load image " + file);
            System.out.println(e);
            return null;
        }
        if (mt.isErrorAny()) {
            System.out.println("Couldn't load image " + file);
            return null;
        }

//         ImageObserver observer = new ImageObserver() {
//             public boolean imageUpdate(Image img,int flags,int x,int y,int w,int h) {
//                 if ((flags & (ALLBITS | FRAMEBITS | ABORT)) != 0) {
//                     synchronized (this) { notify(); }
//                     return false;
//                 }
//                 return true;
//             }
//         };
//         try {
//             synchronized (observer) {
//                 while (!toolkit.prepareImage(img,-1,-1,observer)) { observer.wait(); }
//             }
//         }
//         catch (InterruptedException e) {
//             System.out.println("Couldn't load image "+file);
//             return null;
//         }
        //System.out.println("image width "+ img.getWidth(comp) +
        //		   " height " + img.getHeight(comp));
        BufferedImage bimg =
                comp.getGraphicsConfiguration().createCompatibleImage(img.getWidth(comp),
                img.getHeight(comp),
                Transparency.TRANSLUCENT);
        bimg.getGraphics().drawImage(img, 0, 0, comp);
        return bimg;
    }
 
开发者ID:heqichen,项目名称:openblocks,代码行数:56,代码来源:ImageManager.java

示例11: IconWithGif

import java.awt.MediaTracker; //导入方法依赖的package包/类
/**
 * Initialize the icon and load its image. By changing the global parameter
 * "icontype", png can be used too.
 */
public IconWithGif (IconBar bar, String file)
{
	super(bar, file);
	String iconfile = getDisplay(file);
	if ( !iconfile.equals("")) file = iconfile;
	try
	{
		InputStream in = getClass().getResourceAsStream(
			Bar.Resource + file + "."
				+ Global.getParameter("icontype", "gif"));
		int pos = 0;
		int n = in.available();
		byte b[] = new byte[20000];
		while (n > 0)
		{
			int k = in.read(b, pos, n);
			if (k < 0) break;
			pos += k;
			n = in.available();
		}
		in.close();
		I = Toolkit.getDefaultToolkit().createImage(b, 0, pos);
		MediaTracker T = new MediaTracker(bar);
		T.addImage(I, 0);
		T.waitForAll();
	}
	catch (Exception e)
	{
		try
		{
			I = getToolkit().getImage(
				file + "." + Global.getParameter("icontype", "gif"));
			MediaTracker mt = new MediaTracker(this);
			mt.addImage(I, 0);
			mt.waitForID(0);
			if ( !(mt.checkID(0) && !mt.isErrorAny()))
				throw new Exception("");
		}
		catch (Exception ex)
		{
			I = null;
			return;
		}
	}
	W = I.getWidth(this);
	H = I.getHeight(this);
	X = Size / 2 - W / 2;
	Y = Size / 2 - H / 2;
}
 
开发者ID:Zenigata,项目名称:jago,代码行数:54,代码来源:IconBar.java


注:本文中的java.awt.MediaTracker.isErrorAny方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。