use of java.awt.MediaTracker in project Aspose.BarCode-for-Java by aspose-barcode.
the class MyBarCode method paint.
public void paint(Graphics g) {
// The path to the resource directory.
String dataDir = Utils.getDataDir(MyBarCode.class) + "BarcodeImage/RenderingFeatures/";
String fileName = dataDir + "barcode.png";
BarCodeBuilder bb = new BarCodeBuilder();
bb.setEncodeType(com.aspose.barcode.EncodeTypes.CODE_128);
bb.setCodeText("12345678");
bb.save(fileName);
// Load and Draw the image on applet
MediaTracker tr = new MediaTracker(this);
File sourceimage = new File(fileName);
Image image;
try {
image = ImageIO.read(sourceimage);
tr.addImage(image, 0);
g.drawImage(image, 0, 0, this);
} catch (IOException e) {
e.printStackTrace();
}
}
use of java.awt.MediaTracker in project bioformats by openmicroscopy.
the class AWTImageTools method loadImage.
/**
* Ensures the given AWT image is fully loaded.
*/
public static boolean loadImage(Image image) {
if (image instanceof BufferedImage)
return true;
MediaTracker tracker = new MediaTracker(OBS);
tracker.addImage(image, 0);
try {
tracker.waitForID(0);
} catch (InterruptedException exc) {
return false;
}
if (MediaTracker.COMPLETE != tracker.statusID(0, false))
return false;
return true;
}
use of java.awt.MediaTracker in project ma-core-public by infiniteautomation.
the class ViewGraphicLoader method loadDirectory.
private void loadDirectory(File dir, String baseId) throws Exception {
String id = baseId + dir.getName();
String name = id;
String typeStr = "imageSet";
int width = -1;
int height = -1;
int textX = 5;
int textY = 5;
File[] files = dir.listFiles();
Arrays.sort(files);
List<String> imageFiles = new ArrayList<String>();
for (File file : files) {
if (file.getName().startsWith(".")) {
// ignore '.' files and directories
} else if (file.isDirectory())
loadDirectory(file, id + ".");
else if (IGNORE_THUMBS.equalsIgnoreCase(file.getName())) {
// no op
} else if (INFO_FILE_NAME.equalsIgnoreCase(file.getName())) {
// Info file
Properties props = new Properties();
props.load(new FileInputStream(file));
name = getProperty(props, "name", name);
typeStr = getProperty(props, "type", "imageSet");
width = getIntProperty(props, "width", width);
height = getIntProperty(props, "height", height);
textX = getIntProperty(props, "text.x", textX);
textY = getIntProperty(props, "text.y", textY);
} else {
// Image file. Subtract the load path from the image path
String imagePath = file.getPath().substring(path.length());
// Replace Windows-style '\' path separators with '/'
imagePath = imagePath.replaceAll("\\\\", "/");
imageFiles.add(imagePath);
}
}
if (!imageFiles.isEmpty()) {
if (width == -1 || height == -1) {
String imagePath = path + imageFiles.get(0);
Image image = Toolkit.getDefaultToolkit().getImage(imagePath);
MediaTracker tracker = new MediaTracker(new Container());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (width == -1)
width = image.getWidth(null);
if (height == -1)
height = image.getHeight(null);
if (width == -1 || height == -1)
throw new Exception("Unable to derive image dimensions from " + imagePath);
}
String[] imageFileArr = imageFiles.toArray(new String[imageFiles.size()]);
ViewGraphic g;
if ("imageSet".equals(typeStr))
g = new ImageSet(id, name, imageFileArr, width, height, textX, textY);
else if ("dynamic".equals(typeStr))
g = new DynamicImage(id, name, imageFileArr[0], width, height, textX, textY);
else
throw new Exception("Invalid type: " + typeStr);
viewGraphics.add(g);
}
}
use of java.awt.MediaTracker in project lwjgl by LWJGL.
the class AppletLoader method getImage.
/**
* 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;
}
use of java.awt.MediaTracker in project scriptographer by scriptographer.
the class Image method waitForImage.
public static java.awt.Image waitForImage(java.awt.Image image) {
MediaTracker mediaTracker = new MediaTracker(new Container());
mediaTracker.addImage(image, 0);
try {
mediaTracker.waitForID(0);
if (image.getWidth(null) == -1 || image.getHeight(null) == -1)
image = null;
} catch (InterruptedException e) {
image = null;
}
return image;
}
Aggregations