Ejemplo n.º 1
0
  /**
   * Creates a new JpegEncoder object.
   *
   * @param image DOCUMENT ME!
   * @param quality DOCUMENT ME!
   * @param tOut DOCUMENT ME!
   */
  public JpegEncoder(Image image, int quality, OutputStream tOut) {
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(image, 0);

    try {
      tracker.waitForID(0);
    } catch (InterruptedException e) {
      // Got to do something?
    }

    /*
     * Quality of the image.
     * 0 to 100 and from bad image quality, high compression to good
     * image quality low compression
     */
    Quality = quality;

    /*
     * Getting picture information
     * It takes the Width, Height and RGB scans of the image.
     */
    JpegObj = new JpegInfo(image);

    imageHeight = JpegObj.imageHeight;
    imageWidth = JpegObj.imageWidth;

    // CoHort: out could be an internal OutputStream, but pointless,
    //  since I pass it a OutputStream already.
    out = tOut;
    dct = new DCT(Quality);
    Huf = new Huffman(imageWidth, imageHeight);
  }
Ejemplo n.º 2
0
 /**
  * Load images (used for preloading images).
  *
  * @param images Array of <code>Image</code> instances to preload.
  * @param comp Component that will observe the loading state of the images.
  */
 public static void loadImages(Image[] images, Component comp) {
   MediaTracker tracker = new MediaTracker(comp);
   for (int i = 0; i < images.length; i++) tracker.addImage(images[i], 0);
   try {
     tracker.waitForID(0);
   } catch (InterruptedException ignore) {
   }
 }
  /** Make (scale down) the thumbnail */
  private Image getScaledImage(Image image, int breite, int hoehe) {

    Image scaledImage = image.getScaledInstance(breite, hoehe, Image.SCALE_DEFAULT);

    try {
      MediaTracker mediaTracker = new MediaTracker(new Container());
      mediaTracker.addImage(scaledImage, 0);
      mediaTracker.waitForID(0);

    } catch (InterruptedException e) {

      return null;
    }
    return scaledImage;
  }
  /** Read the thumbnail */
  private Image readImageThumbnail(File fileThumbnail) {

    Image image = null;

    try {
      image = Toolkit.getDefaultToolkit().getImage(fileThumbnail.getPath());
      MediaTracker mediaTracker = new MediaTracker(new Container());
      mediaTracker.addImage(image, 0);
      mediaTracker.waitForID(0);
    } catch (InterruptedException e) {
      //			System.out.println("ERROR: InterruptedException beim Lesen thumbnail (" +
      // fileThumbnail.getPath()
      //					+ "). " + e);
      return null;
    }

    return image;
  }
Ejemplo n.º 5
0
  public static java.awt.image.BufferedImage loadBufferedImageFromResources(
      Component c, String filename) {

    try {
      Misc m = new Misc();
      java.awt.Image img = loadImageFromResources(filename);
      MediaTracker mt = new MediaTracker(c);
      mt.addImage(img, 0);
      mt.waitForID(0);
      int width = img.getWidth(null);
      int height = img.getHeight(null);
      BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      Graphics gg = bi.getGraphics();
      gg.drawImage(img, 0, 0, null);
      gg.dispose();
      return bi;
    } catch (Exception ex) {
      System.out.println(ex.toString());
    }
    return null;
  }
  // ---------------------------------//
  SpriteAnimate() { // constructor
    // Load and track the images
    mediaTracker = new MediaTracker(this);
    // Get and track the background
    // image
    backGroundImage = Toolkit.getDefaultToolkit().getImage("background02.gif");
    mediaTracker.addImage(backGroundImage, 0);

    // Get and track 6 images to use
    // for sprites
    gifImages[0] = Toolkit.getDefaultToolkit().getImage("redball.gif");
    mediaTracker.addImage(gifImages[0], 0);
    gifImages[1] = Toolkit.getDefaultToolkit().getImage("greenball.gif");
    mediaTracker.addImage(gifImages[1], 0);
    gifImages[2] = Toolkit.getDefaultToolkit().getImage("blueball.gif");
    mediaTracker.addImage(gifImages[2], 0);
    gifImages[3] = Toolkit.getDefaultToolkit().getImage("yellowball.gif");
    mediaTracker.addImage(gifImages[3], 0);
    gifImages[4] = Toolkit.getDefaultToolkit().getImage("purpleball.gif");
    mediaTracker.addImage(gifImages[4], 0);
    gifImages[5] = Toolkit.getDefaultToolkit().getImage("orangeball.gif");
    mediaTracker.addImage(gifImages[5], 0);

    // Block and wait for all images to
    // be loaded
    try {
      mediaTracker.waitForID(0);
    } catch (InterruptedException e) {
      System.out.println(e);
    } // end catch

    // Base the Frame size on the size
    // of the background image.
    // These getter methods return -1 if
    // the size is not yet known.
    // Insets will be used later to
    // limit the graphics area to the
    // client area of the Frame.
    int width = backGroundImage.getWidth(this);
    int height = backGroundImage.getHeight(this);

    // While not likely, it may be
    // possible that the size isn't
    // known yet.  Do the following
    // just in case.
    // Wait until size is known
    while (width == -1 || height == -1) {
      System.out.println("Waiting for image");
      width = backGroundImage.getWidth(this);
      height = backGroundImage.getHeight(this);
    } // end while loop

    // Display the frame
    setSize(width, height);
    setVisible(true);
    setTitle("Copyright 2001, R.G.Baldwin");

    // Create and start animation thread
    animationThread = new Thread(this);
    animationThread.start();

    // Anonymous inner class window
    // listener to terminate the
    // program.
    this.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  } // end constructor