本文整理汇总了Java中java.awt.MediaTracker.addImage方法的典型用法代码示例。如果您正苦于以下问题:Java MediaTracker.addImage方法的具体用法?Java MediaTracker.addImage怎么用?Java MediaTracker.addImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.MediaTracker
的用法示例。
在下文中一共展示了MediaTracker.addImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToBufferedImage
import java.awt.MediaTracker; //导入方法依赖的package包/类
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;
}
}
示例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: 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);
}
示例4: 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
}
示例5: getFileAsImage
import java.awt.MediaTracker; //导入方法依赖的package包/类
public Image getFileAsImage(String pathName, String[] retFileNameOrError) {
if (!haveDisplay) {
retFileNameOrError[0] = "no display";
return null;
}
Image image = fileManager.getFileAsImage(pathName, retFileNameOrError);
if (image == null)
return null;
MediaTracker tracker = new MediaTracker(display);
tracker.addImage(image, 0);
try {
tracker.waitForID(0);
} catch (InterruptedException e) {
// Got to do something?
}
return image;
}
示例6: run
import java.awt.MediaTracker; //导入方法依赖的package包/类
/**
*
*/
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", new Integer(10500));
parameters.put("SummaryImage", image);
JasperRunManager.runReportToPdfFile("build/reports/FirstJasper.jasper", parameters, getDemoHsqldbConnection());
System.err.println("PDF running time : " + (System.currentTimeMillis() - start));
}
示例7: Splash
import java.awt.MediaTracker; //导入方法依赖的package包/类
public Splash(Frame parent, String imagefilename, boolean dialog)
{
if (dialog)
{
m_window = new MyDialog(parent);
}
else
{
m_window = new MyWindow(parent);
}
javax.swing.ImageIcon icon = new javax.swing.ImageIcon(getClass().getResource(imagefilename));
m_splashImage = icon.getImage();
MediaTracker loader = new MediaTracker(m_window);
loader.addImage(m_splashImage, 0);
try {
loader.waitForAll();
} catch (Exception e) {}
}
示例8: drawMap
import java.awt.MediaTracker; //导入方法依赖的package包/类
/**
* Creates a 2D map at a given center point.
* @param newCenter the new center location
*/
public void drawMap(Coordinates newCenter) {
if ((newCenter != null) && (!newCenter.equals(currentCenter))) {
mapImage = createMapImage(newCenter);
MediaTracker mt = new MediaTracker(displayArea);
mt.addImage(mapImage, 0);
try {
mt.waitForID(0);
}
catch (InterruptedException e) {
logger.log(Level.SEVERE,Msg.getString("CannedMarsMap.log.mediaTrackerInterrupted") + e); //$NON-NLS-1$
}
mapImageDone = true;
currentCenter = new Coordinates(newCenter);
}
}
示例9: initializeDeaths
import java.awt.MediaTracker; //导入方法依赖的package包/类
private void initializeDeaths(Graphwar graphwar, MediaTracker mediaTracker) throws Exception
{
String filePath = "/rsc/soldierDeath.txt";
BufferedReader read = new BufferedReader(new InputStreamReader(graphwar.getClass().getResourceAsStream(filePath)));
int numImages = Integer.parseInt(GraphUtil.nextLine(read).trim());
deathImages = new Image[numImages];
deathDurations = new int[numImages];
for(int j=0; j<numImages;j++)
{
deathImages[j] = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
deathDurations[j] = Integer.parseInt(GraphUtil.nextLine(read).trim());
mediaTracker.addImage(deathImages[j], 0);
}
deathFadeDuration = Integer.parseInt(GraphUtil.nextLine(read).trim());
}
示例10: loadImage
import java.awt.MediaTracker; //导入方法依赖的package包/类
/**
* java.awt.Image loadImage()
* 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 java.awt.Image img the loaded image
*/
private static Image loadImage() {
System.out.println("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;
}
示例11: makeBackgroundImage
import java.awt.MediaTracker; //导入方法依赖的package包/类
public static JLabel makeBackgroundImage(Graphwar graphwar, BufferedReader read) throws InterruptedException, IOException
{
MediaTracker tracker = new MediaTracker(graphwar);
Image image = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
tracker.addImage(image, 0);
tracker.waitForAll();
int x = Integer.parseInt(GraphUtil.nextLine(read));
int y = Integer.parseInt(GraphUtil.nextLine(read));
JLabel imagePanel = new JLabel(new ImageIcon(image));
imagePanel.setBounds(x, y, image.getWidth(null), image.getHeight(null));
return imagePanel;
}
示例12: makeButton
import java.awt.MediaTracker; //导入方法依赖的package包/类
public static GraphButton makeButton(Graphwar graphwar, BufferedReader read) throws InterruptedException, IOException
{
MediaTracker tracker = new MediaTracker(graphwar);
Image normal = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
tracker.addImage(normal, 0);
Image over = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
tracker.addImage(over, 1);
Image tempImg = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
tracker.addImage(tempImg, 2);
tracker.waitForAll();
BufferedImage mask = new BufferedImage(tempImg.getWidth(null), tempImg.getHeight(null), BufferedImage.TYPE_3BYTE_BGR);
mask.getGraphics().drawImage(tempImg, 0, 0, null);
int x = Integer.parseInt(GraphUtil.nextLine(read));
int y = Integer.parseInt(GraphUtil.nextLine(read));
GraphButton graphButton = new GraphButton(normal, over, mask);
graphButton.setBounds(x, y, normal.getWidth(null), normal.getWidth(null));
return graphButton;
}
示例13: loadPreviewImage
import java.awt.MediaTracker; //导入方法依赖的package包/类
public void loadPreviewImage(Entity entity, Image camo, int tint, BufferedPanel bp) {
Image base = mechTileset.imageFor(entity, comp);
EntityImage entityImage = new EntityImage(base, tint, camo, bp);
Image preview = entityImage.loadPreviewImage();
BackGroundDrawer bgdPreview = new BackGroundDrawer(preview);
bp.removeBgDrawers();
bp.addBgDrawer(bgdPreview);
MediaTracker tracker = new MediaTracker(comp);
tracker.addImage(preview, 0);
try {
tracker.waitForID(0);
} catch (InterruptedException e) {
;
}
}
示例14: 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;
}
示例15: imageToBufferedImage
import java.awt.MediaTracker; //导入方法依赖的package包/类
/**
* Méthode qui convertit une image en BufferedImage.
*
* @param im l'image à convertir
* @return une BufferedImage créée à partir de l'image passée en paramètre
*/
public static BufferedImage imageToBufferedImage(Image im) {
if(im==null) {return null;}
if(im instanceof BufferedImage) {return (BufferedImage) im;}//On tente un simple Cast
//On vérifie que l'image est bien chargée
if(im.getWidth(null)==-1 || im.getHeight(null)==-1) {
MediaTracker tracker = new MediaTracker(new Component(){});
tracker.addImage(im, 0);
try {
tracker.waitForID(0);
} catch (InterruptedException ex1) {
Logger.getLogger(ImageTools.class.getName()).log(Level.SEVERE, null, ex1);
if(im.getWidth(null)==-1 || im.getHeight(null)==-1) return null;
}
}
//On dessine l'image dans un buffer
BufferedImage bi = new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_4BYTE_ABGR);
Graphics bg = bi.createGraphics();
bg.drawImage(im, 0, 0, null);
bg.dispose();
return bi;
}