List of usage examples for java.awt MediaTracker MediaTracker
public MediaTracker(Component comp)
From source file:DoubleBufferedImage.java
public void init() { URL url = null;// w w w. jav a 2 s . c o m try { url = new URL(imageURLString); } catch (MalformedURLException me) { showStatus("Malformed URL: " + me.getMessage()); } originalImage = getImage(url); MediaTracker mt = new MediaTracker(this); mt.addImage(originalImage, 0); try { mt.waitForID(0); } catch (InterruptedException ie) { } imageWidth = originalImage.getWidth(null); imageHeight = originalImage.getHeight(null); dbImage = this.createImage(imageWidth, imageHeight); dbImageGraphics = dbImage.getGraphics(); }
From source file:ImageFrame.java
/** * Set the image from a file.//ww w .j a v a 2s . c o m */ public void setImage(File file) throws IOException { // load the image Image image = getToolkit().getImage(file.getAbsolutePath()); // wait for the image to entirely load MediaTracker tracker = new MediaTracker(this); tracker.addImage(image, 0); try { tracker.waitForID(0); } catch (InterruptedException e) { e.printStackTrace(); } if (tracker.statusID(0, true) != MediaTracker.COMPLETE) { throw new IOException("Could not load: " + file + " " + tracker.statusID(0, true)); } setTitle(file.getName()); setImage(image); }
From source file:RotateImage45Degrees.java
public RotateImage45Degrees(String imageFile) { addNotify();//from w w w. j a va 2 s. co m frameInsets = getInsets(); inputImage = Toolkit.getDefaultToolkit().getImage(imageFile); MediaTracker mt = new MediaTracker(this); mt.addImage(inputImage, 0); try { mt.waitForID(0); } catch (InterruptedException ie) { } sourceBI = new BufferedImage(inputImage.getWidth(null), inputImage.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) sourceBI.getGraphics(); g.drawImage(inputImage, 0, 0, null); AffineTransform at = new AffineTransform(); // scale image at.scale(2.0, 2.0); // rotate 45 degrees around image center at.rotate(45.0 * Math.PI / 180.0, sourceBI.getWidth() / 2.0, sourceBI.getHeight() / 2.0); /* * translate to make sure the rotation doesn't cut off any image data */ AffineTransform translationTransform; translationTransform = findTranslation(at, sourceBI); at.preConcatenate(translationTransform); // instantiate and apply affine transformation filter BufferedImageOp bio; bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); destinationBI = bio.filter(sourceBI, null); int frameInsetsHorizontal = frameInsets.right + frameInsets.left; int frameInsetsVertical = frameInsets.top + frameInsets.bottom; setSize(destinationBI.getWidth() + frameInsetsHorizontal, destinationBI.getHeight() + frameInsetsVertical); show(); }
From source file:BufferedImageMouseDrag.java
DisplayCanvas() { setBackground(Color.white);//from ww w .j a v a 2 s . co m setSize(450, 400); addMouseMotionListener(new MouseMotionHandler()); Image image = getToolkit().getImage("largeJava2sLogo.gif"); MediaTracker mt = new MediaTracker(this); mt.addImage(image, 1); try { mt.waitForAll(); } catch (Exception e) { System.out.println("Exception while loading image."); } if (image.getWidth(this) == -1) { System.out.println("no gif file"); System.exit(0); } bi = new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_ARGB); Graphics2D big = bi.createGraphics(); big.drawImage(image, 0, 0, this); }
From source file:ClipImage.java
public void init() { img = getImage(getURL("largeJava2sLogo.GIF")); try {//from ww w. j a v a 2s . c o m MediaTracker tracker = new MediaTracker(this); tracker.addImage(img, 0); tracker.waitForID(0); } catch (Exception e) { } }
From source file:SplashScreen.java
/** * Create a new splash screen object of the specified image. * The image file is located and referred to through the deployment, not * the local file system; A typical value might be "/com/company/splash.jpg". * /*from ww w .j av a 2 s . c o m*/ * @param imageFileName Name of image file resource to act as splash screen. */ public SplashScreen(String imageFileName) { super(new Frame()); try { Toolkit toolkit = Toolkit.getDefaultToolkit(); URL imageUrl = getClass().getResource(imageFileName); image_ = toolkit.getImage(imageUrl); MediaTracker mediaTracker = new MediaTracker(this); mediaTracker.addImage(image_, 0); mediaTracker.waitForID(0); width_ = image_.getWidth(this); height_ = image_.getHeight(this); Dimension screenSize = toolkit.getScreenSize(); x_ = (screenSize.width - width_) / 2; y_ = (screenSize.height - height_) / 2; } catch (Exception exception) { exception.printStackTrace(); image_ = null; } }
From source file:SlidePuzzle.java
public void run() { if (!m_fAllLoaded) { m_Graphics = getGraphics(); MediaTracker tracker = new MediaTracker(this); logo = getImage(getDocumentBase(), "vjlogo.gif"); tracker.addImage(logo, 0);/*from w w w .j a va 2 s. co m*/ try { tracker.waitForAll(); m_fAllLoaded = !tracker.isErrorAny(); } catch (InterruptedException e) { } if (!m_fAllLoaded) { stop(); m_Graphics.drawString("Error loading images!", 10, 40); return; } } //Clear the screen and draw first image repaint(); //Move the squares while (true) { for (x = 1; x < 9; x++) { //Slow down the animation try { Thread.sleep(350); } catch (InterruptedException e) { } //Move square to next location m_Graphics.copyArea(squares[order[x]].x, squares[order[x]].y, 60, 60, squares[order[x - 1]].x - squares[order[x]].x, squares[order[x - 1]].y - squares[order[x]].y); //Clear most recently copied square m_Graphics.clearRect(squares[order[x]].x, squares[order[x]].y, 60, 60); } //Repaint original graphic after two cycles y++; if (y == 2) { repaint(); y = 0; } } }
From source file:eu.planets_project.tb.impl.data.util.ImageThumbnail.java
/** * Create a reduced jpeg version of an image. The width/height ratio is * preserved./*from w ww . ja v a 2 s. com*/ * * @param data * raw data of the image * @param thumbWidth * maximum width of the reduced image * @param thumbHeight * maximum heigth of the reduced image * @param quality * jpeg quality of the reduced image * @param out * produce a reduced jpeg image if the image represented by data * is bigger than the maximum dimensions of the reduced image, * otherwise data is written to this stream */ public static void createThumb(byte[] data, int thumbWidth, int thumbHeight, OutputStream out) throws Exception { // NOTE that this support JPEG, PNG or GIF only. Image image = Toolkit.getDefaultToolkit().createImage(data); MediaTracker mediaTracker = new MediaTracker(new Frame()); int trackID = 0; mediaTracker.addImage(image, trackID); mediaTracker.waitForID(trackID); if (image.getWidth(null) <= thumbWidth && image.getHeight(null) <= thumbHeight) out.write(data); else createThumb(image, thumbWidth, thumbHeight, out); }
From source file:BufferedImageThread.java
AnimationCanvas() { setBackground(Color.green);// w w w . ja v a 2s. c o m setSize(450, 400); image = getToolkit().getImage("largeJava2sLogo.gif"); MediaTracker mt = new MediaTracker(this); mt.addImage(image, 1); try { mt.waitForAll(); } catch (Exception e) { System.out.println("Exception while loading image."); } if (image.getWidth(this) == -1) { System.out.println("No gif file"); System.exit(0); } rotate = (int) (Math.random() * 360); scale = Math.random() * 1.5; scaleDirection = DOWN; xi = 50.0; yi = 50.0; }
From source file:RasterDemo.java
RasterPanel() { setBackground(Color.white);//from www . ja v a 2 s .co m setSize(450, 400); Image image = getToolkit().getImage("largeJava2sLogo.jpg"); MediaTracker mt = new MediaTracker(this); mt.addImage(image, 1); try { mt.waitForAll(); } catch (Exception e) { System.out.println("Exception while loading image."); } if (image.getWidth(this) == -1) { System.out.println("No jpg file"); System.exit(0); } bi1 = new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_ARGB); Graphics2D big = bi1.createGraphics(); big.drawImage(image, 0, 0, this); bi = bi1; }