本文整理匯總了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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
}
示例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");
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}