本文整理汇总了Java中java.awt.MediaTracker.isErrorID方法的典型用法代码示例。如果您正苦于以下问题:Java MediaTracker.isErrorID方法的具体用法?Java MediaTracker.isErrorID怎么用?Java MediaTracker.isErrorID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.MediaTracker
的用法示例。
在下文中一共展示了MediaTracker.isErrorID方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import java.awt.MediaTracker; //导入方法依赖的package包/类
public void init() {
Button b = new Button("Start");
b.addActionListener(this);
setLayout(new BorderLayout());
add(b, BorderLayout.NORTH);
add(p = new Panel(), BorderLayout.CENTER);
p.setLayout(null);
String imgName = getParameter("imagefile");
if (imgName == null) imgName = "duke.gif";
img = getImage(getCodeBase(), imgName);
MediaTracker mt = new MediaTracker(this);
mt.addImage(img, 0);
try {
mt.waitForID(0);
} catch(InterruptedException e) {
throw new IllegalArgumentException(
"InterruptedException while loading image " + imgName);
}
if (mt.isErrorID(0)) {
throw new IllegalArgumentException(
"Couldn't load image " + imgName);
}
v = new Vector<Sprite>(); // multithreaded, use Vector
}
示例2: createSystemImage
import java.awt.MediaTracker; //导入方法依赖的package包/类
public Image createSystemImage(URL url) throws IOException {
java.awt.Image resultImage = Toolkit.getDefaultToolkit().createImage(url);
// TODO not elegant solution, maybe use ImageObserver in
// image.getWitdth(..) instead
MediaTracker mediaTracker = new MediaTracker(new java.awt.Canvas());
mediaTracker.addImage(resultImage, 0);
try {
mediaTracker.waitForID(0);
} catch (InterruptedException ex) {
}
if (mediaTracker.isErrorID(0)) {
throw new IOException();
}
return new J2SEImmutableImage(resultImage);
}
示例3: readImage
import java.awt.MediaTracker; //导入方法依赖的package包/类
/**
* load the image, waiting for it to be fully downloaded
*
* @param fnm
* @return
*/
private Image readImage(String fnm) {
Image image = Toolkit.getDefaultToolkit().getImage(
getClass().getClassLoader().getResource(IMAGE_DIR + fnm));
MediaTracker imageTracker = new MediaTracker(new JPanel());
imageTracker.addImage(image, 0);
try {
imageTracker.waitForID(0);
} catch (InterruptedException e) {
return null;
}
if (imageTracker.isErrorID(0))
return null;
return image;
}
示例4: loadImage
import java.awt.MediaTracker; //导入方法依赖的package包/类
/**
* loads the image of this object
*
* @param textField the textField-instance
* @param location the location to use
* @return the image if successfull, null otherwise
*/
private Image loadImage(AbstractTextField textField,URL location) {
Image img = null;
MediaTracker mt = new MediaTracker(textField);
try {
img = Toolkit.getDefaultToolkit().getImage(location);
mt.addImage(img,0);
mt.waitForAll();
}
catch(InterruptedException e) {
}
return mt.isErrorID(0) ? null : img;
}
示例5: readImage
import java.awt.MediaTracker; //导入方法依赖的package包/类
@Override
public Image readImage(byte[] bytes) throws JRException
{
Image image = Toolkit.getDefaultToolkit().createImage(bytes);
MediaTracker tracker = new MediaTracker(new Panel());
tracker.addImage(image, 0);
try
{
tracker.waitForID(0);
}
catch (Exception e)
{
//image = null;
throw new JRException(e);
}
if(tracker.isErrorID(0))
{
throw
new JRException(
EXCEPTION_MESSAGE_KEY_IMAGE_READ_FAILED,
(Object[])null);
}
return image;
}
示例6: getImage
import java.awt.MediaTracker; //导入方法依赖的package包/类
public Image getImage(String imageSource) {
try {
URL sourceURL = new URL(imageSource);
if (sourceURL.getProtocol().equals("file") &&
!(new File(sourceURL.getPath())).exists()) {
ErrorDialog.showError(this, "File not found: " + imageSource);
return null;
}
Image other = Toolkit.getDefaultToolkit().createImage(sourceURL);
MediaTracker tracker = new MediaTracker(this);
int imageId = 0;
tracker.addImage(other, imageId);
tracker.waitForID(0);
boolean isError = tracker.isErrorID(imageId);
if (isError) {
ErrorDialog.showError(this,
"There were problems reading the background image: " +
imageSource);
return null;
}
return other;
} catch (IOException e) {
throw new OntopiaRuntimeException(e);
} catch (InterruptedException ie) {
throw new OntopiaRuntimeException("InterruptedException caused during" +
" wallpaper_image error check.", ie);
}
}
示例7: toBufferedImageUsingToolkit
import java.awt.MediaTracker; //导入方法依赖的package包/类
/**
* Create image from bytes using AWT toolkit.
* Seems to be faster than ImageIO...
* @param cover image bytes
* @return buffered image
*/
BufferedImage toBufferedImageUsingToolkit(byte[] bytes) throws IOException {
if (TOOLKIT == null) {
return null;
}
Image image = TOOLKIT.createImage(bytes);
MediaTracker mediaTracker = new MediaTracker(new Component() {
private static final long serialVersionUID = 1L;
});
mediaTracker.addImage(image, 0);
try {
mediaTracker.waitForID(0, 0);
} catch (InterruptedException e) {
return null;
}
if (mediaTracker.isErrorID(0)) { // error -> use ImageIO
throw new IOException("Failed to load toolkit image");
} else {
BufferedImage bufferedImage =
new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bufferedImage.createGraphics();
g2d.drawImage(image, 0, 0, null);
g2d.dispose();
image.flush();
return bufferedImage;
}
}
示例8: load
import java.awt.MediaTracker; //导入方法依赖的package包/类
/**
* 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");
}
示例9: getImage
import java.awt.MediaTracker; //导入方法依赖的package包/类
private Image getImage(InputStream is) throws IOException {
byte[] imageBytes = new byte[1024];
int num;
ByteArrayOutputStream ba = new ByteArrayOutputStream();
while ((num = is.read(imageBytes)) != -1) {
ba.write(imageBytes, 0, num);
}
java.awt.Image image = Toolkit.getDefaultToolkit().createImage(ba.toByteArray());
ImageFilter filter = null;
if (isColor()) {
if (backgroundColor.getRed() != 255 || backgroundColor.getGreen() != 255
|| backgroundColor.getBlue() != 255 || foregroundColor.getRed() != 0
|| foregroundColor.getGreen() != 0 || foregroundColor.getBlue() != 0) {
filter = new RGBImageFilter();
}
} else {
if (numColors() == 2) {
filter = new BWImageFilter();
} else {
filter = new GrayImageFilter();
}
}
java.awt.Image resultImage;
if (filter != null) {
FilteredImageSource imageSource = new FilteredImageSource(image.getSource(), filter);
resultImage = Toolkit.getDefaultToolkit().createImage(imageSource);
} else {
resultImage = image;
}
// TODO not elegant solution, maybe use ImageObserver in
// image.getWitdth(..) instead
MediaTracker mediaTracker = new MediaTracker(new java.awt.Canvas());
mediaTracker.addImage(resultImage, 0);
try {
mediaTracker.waitForID(0);
} catch (InterruptedException ex) {
}
if (mediaTracker.isErrorID(0)) {
throw new IOException();
}
return new J2SEImmutableImage(resultImage);
}