Ejemplo n.º 1
0
  DisplayCanvas() {
    setBackground(Color.white);
    setSize(450, 400);
    addMouseMotionListener(new MouseMotionHandler());

    Image image =
        getToolkit().getImage("D:\\Workspaces\\ADTJunoWorkspace\\Snippets\\images\\qr.png");

    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);
  }
Ejemplo n.º 2
0
  /**
   * Load the image located at URL.
   *
   * @param url URL where the image file is located.
   * @return loaded image at path or url
   * @see java.io.File#toURI()
   */
  public static synchronized Image loadImage(URL url) {
    Image image = null;
    image = Toolkit.getDefaultToolkit().getImage(url);
    if (image != null) {
      s_tracker.addImage(image, 0);
      try {
        s_tracker.waitForAll();
      } catch (InterruptedException e) {
        log.severe("Url= " + url + " - " + e.getMessage());
        s_tracker.removeImage(image);
        image = null;
      } finally {
        if (image != null) s_tracker.removeImage(image);
        if (s_tracker.isErrorAny()) {
          log.severe("Tracker: " + s_tracker.getErrorsAny()[0]);
          image = null;
        }

        if (image != null) {
          if (image.getWidth(null) < 0 || image.getHeight(null) < 0) {
            log.severe("Image=0");
            image = null;
          }
        }
      }
    }
    return image;
  } //  loadImage
Ejemplo n.º 3
0
  public myImageFade() {
    myImage1 = Toolkit.getDefaultToolkit().getImage("d:/1.jpg");
    myImage2 = Toolkit.getDefaultToolkit().getImage("d:/ball.gif");

    myImage1_scaled = myImage1.getScaledInstance(500, 500, Image.SCALE_FAST);
    myImage2_scaled = myImage2.getScaledInstance(500, 500, Image.SCALE_FAST);
    repaint();

    try {
      MediaTracker mt = new MediaTracker(this);
      mt.addImage(myImage1, 0);
      mt.addImage(myImage2, 0);
      mt.waitForAll();

      PixelGrabber grab1 =
          new PixelGrabber(myImage1, 0, 0, picWidth, picHeight, m_Img1Pix, 0, picWidth);
      PixelGrabber grab2 =
          new PixelGrabber(myImage2, 0, 0, picWidth, picHeight, m_Img2Pix, 0, picWidth);

      grab1.grabPixels();
      grab2.grabPixels();

      System.out.println(m_Img1Pix.length);

      System.out.println(m_Img1Pix[18500]);

      m_ImgSrc = new MemoryImageSource(picWidth, picHeight, m_Pix, 0, picWidth);
      m_ImgSrc.setAnimated(true);
      m_Img = createImage(m_ImgSrc);
    } catch (InterruptedException e) {
    }
  }
  AnimationCanvas() {
    setBackground(Color.green);
    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;
  }
Ejemplo n.º 5
0
  public ToolButton(PaletteListener listener, String iconName, String name, Tool tool) {
    super(listener);
    tool.addToolListener(this);
    setEnabled(tool.isUsable());

    // use a Mediatracker to ensure that all the images are initially loaded
    Iconkit kit = Iconkit.instance();
    if (kit == null) {
      throw new JHotDrawRuntimeException("Iconkit instance isn't set");
    }

    Image im[] = new Image[3];
    im[0] = kit.loadImageResource(iconName + "1.gif");
    im[1] = kit.loadImageResource(iconName + "2.gif");
    im[2] = kit.loadImageResource(iconName + "3.gif");

    MediaTracker tracker = new MediaTracker(this);
    for (int i = 0; i < 3; i++) {
      tracker.addImage(im[i], i);
    }
    try {
      tracker.waitForAll();
    } catch (Exception e) {
      // ignore exception
    }

    fIcon = new PaletteIcon(new Dimension(24, 24), im[0], im[1], im[2]);
    fTool = tool;
    fName = name;

    setIcon(new ImageIcon(im[0]));
    setPressedIcon(new ImageIcon(im[1]));
    setSelectedIcon(new ImageIcon(im[2]));
    setToolTipText(name);
  }
  // public static void initializeRAY_ROTATION_IMAGES(){
  // for (int i = 0; i < 360;i++){
  // ROTATING_RAY1[i] = MANIPULATE_IMAGE.ROTATE(WI[23], i);
  // ROTATING_RAY2[i] = MANIPULATE_IMAGE.ROTATE(WI[24], i);
  // }
  // }
  public static void LOAD(JPanel panel) {
    initializeWELCOME_IMAGES();
    MediaTracker tracker = new MediaTracker(panel);
    for (int i = 0; i < WI.length; i++) {
      tracker.addImage(WI[i], 0);
      try {
        tracker.waitForAll();
      } catch (InterruptedException x) {
        System.err.println("MediaTracker interrupted!");
      }
    }
    for (int i = 0; i < WTI.length; i++) {

      tracker.addImage(WTI[i], 0);
      try {
        tracker.waitForAll();
      } catch (InterruptedException x) {
        System.err.println("MediaTracker interrupted!");
      }
    }
    // initializeRAY_ROTATION_IMAGES();
    /*for (int i = 0;i < ROTATING_RAY1.length; i++) {

    		tracker.addImage( ROTATING_RAY1[i], 0 );
    			try
    			{
    				tracker.waitForAll();
    			}
    			catch( InterruptedException x )
    			{
    				System.err.println( "MediaTracker interrupted!" );
    			}
    }
    	for (int i = 0;i < ROTATING_RAY2.length; i++) {

    		tracker.addImage( ROTATING_RAY2[i], 0 );
    			try
    			{
    				tracker.waitForAll();
    			}
    			catch( InterruptedException x )
    			{
    				System.err.println( "MediaTracker interrupted!" );
    			}
    }  */

  }
Ejemplo n.º 7
0
  /**
   * Обучение перцептрона
   *
   * @param path
   * @param n - количество циклов обучения
   */
  public void teach(String path, int n) {

    class JPGFilter implements FilenameFilter {
      public boolean accept(File dir, String name) {
        return (name.endsWith(".jpg"));
      }
    }

    // загрузка всех тестовых изображений в массив img[]
    String[] list = new File(path + "/").list(new JPGFilter());
    Image[] img = new Image[list.length];
    MediaTracker mediaTracker = new MediaTracker(new Container());
    int i = 0;
    for (String s : list) {
      img[i] = java.awt.Toolkit.getDefaultToolkit().createImage(path + "/" + s);

      mediaTracker.addImage(img[i], 0);
      try {
        mediaTracker.waitForAll();
      } catch (InterruptedException ex) {
        Logger.getLogger(Teacher.class.getName()).log(Level.SEVERE, null, ex);
      }

      i++;
    }

    // инициализация начальных весов, если ещё не были проинициализированы
    if (!perceptron.isWeightsWasInitialized()) {
      perceptron.initWeights();
    }

    // получение пиксельных массивов каждого изображения
    // и обучение n раз каждой выборке
    PixelGrabber pg;
    int[] pixels, x, y;
    int w, h, k = 0;
    while (n-- > 0) {
      for (int j = 0; j < img.length; j++) {
        w = img[j].getWidth(null);
        h = img[j].getHeight(null);

        if (w * h > perceptron.getM()) continue;

        pixels = new int[w * h];
        pg = new PixelGrabber(img[j], 0, 0, w, h, pixels, 0, w);
        try {
          pg.grabPixels();
        } catch (InterruptedException ex) {
          Logger.getLogger(Teacher.class.getName()).log(Level.SEVERE, null, ex);
        }

        // получение векторов и обучение перцептрона
        x = getInVector(pixels);
        y = getOutVector(Integer.parseInt(String.valueOf(list[j].charAt(0))));
        perceptron.teach(x, y);
      }
    }
  }
Ejemplo n.º 8
0
  public void updateScreen() {
    boolean olay = false;

    int imageSize = 0;
    URL url = null;
    BufferedInputStream bs = null;
    DataInputStream ds = null;
    int i = 0;

    delay(1000);

    String imageName = new String();
    imageName = "initial.jpg";
    diskWidth = 512;
    diskHeight = 512;
    x = 0;
    y = 0;

    if (screenMode != 5) {
      olay = true;
      read_Overlay(0);
    } else {
      eraseAll();
      olay = false;
    }

    imageSize = diskWidth * diskHeight;

    try {
      url = new URL(codebase, imageName);
    } catch (MalformedURLException e1) {
      System.out.println("URL Error");
    }

    if (screenMode == 6) // Spectrum
    read_Overlay(1);
    else if (screenMode == 7) // X-Ray Map
    getJpegImage(url, x, y, diskWidth, diskHeight);
    else if (screenMode != 9) // All else
    readJpegImage(url, x, y, diskWidth, diskHeight);

    if (screenMode != 7) // Combine Mem and Overlay except for X-Ray Map
    combine_Mem_Olay(screenMode, olay);

    MemoryImageSource mis = new MemoryImageSource(512, 512, pixel, 0, 512);
    image = createImage(mis);
    tracker.addImage(image, 0, 512, 512);

    try {
      tracker.waitForAll();
    } catch (InterruptedException e) {
    }

    repaint();

    tracker.removeImage(image, 0);
  }
Ejemplo n.º 9
0
 /*		Konstruktor
  *
  *		arg:	fname = Dateiname des Bildes
  *				width, height = Breite und Hoehe der Icons in Pixels
  */
 public IconBitmap(Image img, int width, int height) {
   this.img = img;
   d = new Dimension(width, height);
   MediaTracker mt = new MediaTracker(this);
   mt.addImage(img, 0);
   try {
     mt.waitForAll();
   } catch (InterruptedException ex) {
     // nothing
   }
   cols = img.getWidth(this) / d.width;
   rows = img.getHeight(this) / d.height;
 }
  /** Retrieve all images. This thread will self-terminate once all are loaded. */
  public void run() {
    // The media Tracker ensures all images are fully loaded: This avoids the
    // arbitrary race conditions that may happen when running a plugin before all
    // images have been properly loaded,
    java.awt.MediaTracker mt = new java.awt.MediaTracker(peer);

    // Create a CardImages to house the deck of card images.
    CardImages ci = new CardImages();

    CardEnumeration ce = new CardEnumeration();
    int idx = 1;
    while (ce.hasMoreElements()) {
      Card c = (Card) ce.nextElement();
      String key = c.getName();

      // extract from resource file (prepend images directory)
      try {
        File f = new File(imageDirectory + deckType + "/" + key + ".gif");
        java.net.URL url = f.toURI().toURL();

        // java.net.URL url = this.getClass().getResource (str);
        Image img = java.awt.Toolkit.getDefaultToolkit().getImage(url);
        mt.addImage(img, idx++);
        ci.setCardImage(c, img);
      } catch (MalformedURLException mue) {
        return;
      }
    }

    // Also get Back (already in the images directory)
    try {
      File f = new File(imageDirectory + deckType + "/" + backResourceName + ".gif");
      java.net.URL url = f.toURI().toURL();
      Image img = java.awt.Toolkit.getDefaultToolkit().getImage(url);
      mt.addImage(img, idx++);
      ci.setCardReverse(img);
    } catch (MalformedURLException mue) {
      return;
    }

    try {
      mt.waitForAll();
    } catch (InterruptedException ie) {
    }

    // keep around so thread can return this value in synchronized method getLoadedCardImages
    loadedImages = ci;

    // we are done.
    readyStatus = true;
  }
Ejemplo n.º 11
0
  /**
   * We need to load animated .gifs through this mechanism vs. getImage due to a number of bugs in
   * Java's image loading routines.
   *
   * @param name The path of the image
   * @param who The component that will use the image
   * @return the loaded image object
   */
  public static Image getDirectImage(String name, Component who) {
    Image image = null;

    // try to get the URL as a system resource
    URL url = ClassLoader.getSystemResource(name);
    try {
      image = Toolkit.getDefaultToolkit().createImage(url);
      MediaTracker tracker = new MediaTracker(who);
      tracker.addImage(image, 0);
      tracker.waitForAll();
    } catch (InterruptedException e) {
    }
    return image;
  }
Ejemplo n.º 12
0
 private void ensureImageLoaded(final Image anImage) {
   if (anImage.getWidth(this) != -1) {
     return;
   }
   final MediaTracker tracker = new MediaTracker(this);
   tracker.addImage(anImage, 1);
   try {
     tracker.waitForAll(1);
   } catch (final InterruptedException ie) {
     ie.printStackTrace();
     System.err.println("<<<<<<<<<<<<<<<<<<<<<<>trying again to load Image");
     ensureImageLoaded(anImage);
   }
 }
Ejemplo n.º 13
0
 public static void ensureLoaded(Image img) throws Exception {
   // System.err.println("In ensureloaded");
   mediatracker.addImage(img, 0);
   try {
     mediatracker.waitForAll();
     if (mediatracker.getErrorsAny() != null) {
       mediatracker.removeImage(img);
       throw new Exception("Error loading image");
     }
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   mediatracker.removeImage(img);
   // System.err.println("Out ensureloaded");
 }
Ejemplo n.º 14
0
 /**
  * This method paints the canvas.
  *
  * @param g Graphics: this is the graphical environment.
  */
 public void paint(Graphics g) {
   Toolkit toolkit = Toolkit.getDefaultToolkit();
   URL url = getClass().getResource("desenvolupament.png");
   Image image = toolkit.getImage(url);
   MediaTracker mediaTracker = new MediaTracker(this);
   mediaTracker.addImage(image, 0);
   try {
     mediaTracker.waitForAll();
     if (mediaTracker.checkAll()) {
       g.drawImage(image, 0, 0, this);
     }
   } catch (InterruptedException e) {
     System.out.println("No puc amb la imatge!");
   }
 }
Ejemplo n.º 15
0
 void setIcon() {
   try {
     Image image;
     MediaTracker tracker = new MediaTracker(this);
     URL url = getClass().getResource("/images/mufficon.jpg");
     Object obj;
     if (url != null && ((obj = url.getContent()) instanceof ImageProducer)) {
       image = Toolkit.getDefaultToolkit().createImage((ImageProducer) obj);
       tracker.addImage(image, 1);
       tracker.waitForAll();
       setIconImage(image);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 16
0
 public static Image getGameIcon(final Window frame) {
   Image img = null;
   try {
     img = frame.getToolkit().getImage(GameRunner2.class.getResource("ta_icon.png"));
   } catch (final Exception ex) {
     System.out.println("icon not loaded");
   }
   final MediaTracker tracker = new MediaTracker(frame);
   tracker.addImage(img, 0);
   try {
     tracker.waitForAll();
   } catch (final InterruptedException ex) {
     ex.printStackTrace();
   }
   return img;
 }
Ejemplo n.º 17
0
  /**
   * イメージをロードする。
   *
   * @param panel パネルへの参照。
   */
  private void loadImage(MainPanel panel) {
    MediaTracker tracker = new MediaTracker(panel);

    // 台車のイメージを読み込む
    cartImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("cart.gif"));
    tracker.addImage(cartImage, 0);

    try {
      tracker.waitForAll();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    // 台車の大きさ
    cartWidth = cartImage.getWidth(panel);
    cartHeight = cartImage.getHeight(panel);
  }
Ejemplo n.º 18
0
 public ImageRGB(byte[] imagedata, Component component) {
   try {
     Image image = Toolkit.getDefaultToolkit().createImage(imagedata);
     MediaTracker mediaTracker = new MediaTracker(component);
     mediaTracker.addImage(image, 0);
     mediaTracker.waitForAll();
     width = image.getWidth(component);
     height = image.getHeight(component);
     maxWidth = width;
     maxHeight = height;
     offsetX = 0;
     offsetY = 0;
     pixels = new int[width * height];
     PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
     pixelgrabber.grabPixels();
   } catch (Exception exception) {
     System.out.println("Error converting jpg");
   }
 }
    private void init() {
      credits.add(new CreditsEntry(true, "Programmierung"));
      credits.add(new CreditsEntry(false, "Maj0r"));
      credits.add(new CreditsEntry(false, "([email protected])"));
      credits.add(new CreditsEntry(false, "loevenwong"));
      credits.add(new CreditsEntry(false, "([email protected])"));
      credits.add(new CreditsEntry(true, "Besonderen Dank an"));
      credits.add(new CreditsEntry(false, "muhviehstarr"));
      credits.add(new CreditsEntry(true, "Banner & Bilder"));
      credits.add(new CreditsEntry(false, "saschxd"));
      credits.add(new CreditsEntry(true, "Übersetzung"));
      credits.add(new CreditsEntry(false, "BlueTiger"));
      credits.add(new CreditsEntry(false, "nurseppel"));
      credits.add(new CreditsEntry(true, "Kontakt"));
      credits.add(new CreditsEntry(false, "irc.devStaff.net:6667"));
      credits.add(new CreditsEntry(false, "#applejuice"));
      credits.add(new CreditsEntry(false, "www.applejuicenet.de"));

      backgroundImage = IconManager.getInstance().getIcon("applejuiceinfobanner").getImage();
      flagge = IconManager.getInstance().getIcon("deutsch").getImage();
      MediaTracker mt = new MediaTracker(this);

      mt.addImage(backgroundImage, 0);
      try {
        mt.waitForAll();
      } catch (InterruptedException x) {

        // kein Bild da, dann kack drauf ;-)
      }

      version.setText(
          "Version " + AppleJuiceDialog.GUI_VERSION + "/" + ApplejuiceFassade.FASSADE_VERSION);
      Font font = version.getFont();

      font = new Font(font.getName(), Font.PLAIN, font.getSize());
      version.setFont(font);
      setLayout(new BorderLayout());
      TKLPanel panel1 = new TKLPanel(new FlowLayout(FlowLayout.RIGHT));

      panel1.add(version);
      panel1.setOpaque(false);
      add(panel1, BorderLayout.SOUTH);
    }
Ejemplo n.º 20
0
  public getPicInfo(Frame father) {
    try {
      FileDialog diag = new FileDialog(father);
      diag.setVisible(true);
      m_Img =
          getToolkit()
              .getImage(diag.getDirectory() + diag.getFile())
              .getScaledInstance(W, H, Image.SCALE_SMOOTH);
      MediaTracker mt = new MediaTracker(this);
      mt.addImage(m_Img, 0);
      mt.waitForAll();
      PixelGrabber grab = new PixelGrabber(m_Img, 0, 0, W, H, m_Pix, 0, W);
      grab.grabPixels();
      m_ImgSrc = new MemoryImageSource(W, H, m_Pix, 0, W);
      m_Img = createImage(m_ImgSrc);
      System.out.println("Wait HERE !");
    } catch (InterruptedException e) {

    }
  }
Ejemplo n.º 21
0
  private static BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
      return (BufferedImage) image;

    } else {
      MediaTracker tracker = new MediaTracker(null /*not sure how this is used*/);
      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_RGB);

      Graphics g = bufImage.createGraphics();
      g.drawImage(image, 0, 0, null);
      return bufImage;
    }
  }
Ejemplo n.º 22
0
  public static BufferedImage getImage(String name, Component who) {
    BufferedImage image = null;

    // try to get the URL as a system resource
    URL url = ClassLoader.getSystemResource(name);
    try {
      image = ImageIO.read(url);
      MediaTracker tracker = new MediaTracker(who);
      tracker.addImage(image, 0);
      tracker.waitForAll();
      BufferedImage img2 =
          new BufferedImage(
              image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
      img2.getGraphics().drawImage(image, 0, 0, null);
      image = img2;
    } catch (InterruptedException e) {
    } catch (IOException ioe) {
    } catch (IllegalArgumentException iae) {
    }
    return image;
  }
Ejemplo n.º 23
0
 public Sprite(byte abyte0[], Component component) {
   try {
     // Image image = Toolkit.getDefaultToolkit().getImage(location+"mopar.jpg");
     Image image = Toolkit.getDefaultToolkit().createImage(abyte0);
     MediaTracker mediatracker = new MediaTracker(component);
     mediatracker.addImage(image, 0);
     mediatracker.waitForAll();
     myWidth = image.getWidth(component);
     myHeight = image.getHeight(component);
     anInt1444 = myWidth;
     anInt1445 = myHeight;
     anInt1442 = 0;
     anInt1443 = 0;
     myPixels = new int[myWidth * myHeight];
     PixelGrabber pixelgrabber =
         new PixelGrabber(image, 0, 0, myWidth, myHeight, myPixels, 0, myWidth);
     pixelgrabber.grabPixels();
   } catch (Exception _ex) {
     System.out.println("Error converting jpg");
   }
 }
Ejemplo n.º 24
0
  public Pantalla(IControlador controlador, int tasaRefresco, int pixelesUnidad) {
    if (controlador == null) {
      throw new IllegalArgumentException("Error gráfico: el controlador no puede ser nulo");
    }
    if ((tasaRefresco <= 0) || (tasaRefresco > 1000)) {
      throw new IllegalArgumentException(
          "Error gráfico: la tasa de refresco debe estar entre 1 y 1000");
    }
    if (pixelesUnidad <= 0) {
      throw new IllegalArgumentException(
          "Error gráfico: el valor de píxeles por unidad debe ser mayor que 0");
    }
    this.controlador = controlador;

    this.tasa = tasaRefresco;

    this.pixelesUnidad = pixelesUnidad;

    this.hiloRefresco = new Hilo(tasaRefresco);

    this.localizador = new LocalizadorImagenes(new File("imagenes/"), this);

    this.noImagen = Toolkit.getDefaultToolkit().getImage(getClass().getResource("no-imagen.png"));

    this.colorSuelo = Color.LIGHT_GRAY;

    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(this.noImagen, 0);
    try {
      tracker.waitForAll();
    } catch (InterruptedException localInterruptedException) {
    }
    enableEvents(64L);
    try {
      jbInit();
    } catch (Exception e) {
      e.printStackTrace();
    }
    setVisible(true);
  }
Ejemplo n.º 25
0
  /**
   * Konstruktor MapView Aufgabe ist das Setzen der WorldMap und die Hintergrundgrafik (Landkarte)
   * zu setzen.
   *
   * @param worldMap Zum View gehoerige Instanz der Klasse WorldMap.
   */
  public MapView(WorldMap worldMap) {

    this.worldMap = worldMap;
    this.territoryBattle = new ArrayList<Territory>();
    this.setLayout(null);

    String path = System.getProperty("java.class.path") + "/risk/maps/" + worldMap.getGraphic();
    // String path = "/home/swa/Desktop/maps/"+worldMap.getGraphic();

    MediaTracker mt = new MediaTracker(this);
    this.img = Toolkit.getDefaultToolkit().getImage(path);
    mt.addImage(this.img, 0);
    try {
      mt.waitForAll();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    this.setPreferredSize(new Dimension(img.getWidth(null), img.getHeight(null)));

    this.setVisible(true);
  }
Ejemplo n.º 26
0
  /**
   * Loads an image using the fileName as the full path, returning the constructed and completely
   * loaded Image. Note that all pixels with the colorKey value will be made transparent by setting
   * their alpha values to 0.
   *
   * @param fileName full path and name of the location of the image file to be loaded.
   * @return the loaded Image, with all data fully loaded and with colorKey pixels transparent.
   */
  public BufferedImage loadImageWithColorKey(String fileName, Color colorKey) {
    // LOAD THE IMAGE
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image img = tk.createImage(fileName);

    // WAIT FOR IT TO BE FULLY IN MEMORY
    MediaTracker tracker = new MediaTracker(window);
    tracker.addImage(img, 0);
    try {
      tracker.waitForAll();
    } catch (Exception e) {
      e.printStackTrace();
    }

    // WE'LL PUT IT IN A BufferedImage OBJECT SINCE
    // THAT TYPE OF IMAGE PROVIDES US ACCESS TO
    // ALL OF THE RAW DATA
    BufferedImage imageToLoad =
        new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    Graphics g = imageToLoad.getGraphics();
    g.drawImage(img, 0, 0, null);

    // NOW MAKE ALL PIXELS WITH COLOR (64, 224, 224) TRANSPARENT
    WritableRaster raster = imageToLoad.getRaster();
    int[] dummy = null;
    for (int i = 0; i < raster.getWidth(); i++) {
      for (int j = 0; j < raster.getHeight(); j++) {
        int[] pixel = raster.getPixel(i, j, dummy);
        if ((pixel[0] == colorKey.getRed())
            && (pixel[1] == colorKey.getGreen())
            && (pixel[2] == colorKey.getBlue())) {
          pixel[3] = 0;
          raster.setPixel(i, j, pixel);
        }
      }
    }
    return imageToLoad;
  }
Ejemplo n.º 27
0
 /*
 	This could live in the desktop script.
 	However we'd like to get it on the screen as quickly as possible.
 */
 public static void startSplashScreen() {
   int width = 275, height = 148;
   Window win = new Window(new Frame());
   win.pack();
   BshCanvas can = new BshCanvas();
   can.setSize(width, height); // why is this necessary?
   Toolkit tk = Toolkit.getDefaultToolkit();
   Dimension dim = tk.getScreenSize();
   win.setBounds(dim.width / 2 - width / 2, dim.height / 2 - height / 2, width, height);
   win.add("Center", can);
   Image img = tk.getImage(Interpreter.class.getResource("/bsh/util/lib/splash.gif"));
   MediaTracker mt = new MediaTracker(can);
   mt.addImage(img, 0);
   try {
     mt.waitForAll();
   } catch (Exception e) {
   }
   Graphics gr = can.getBufferedGraphics();
   gr.drawImage(img, 0, 0, can);
   win.setVisible(true);
   win.toFront();
   splashScreen = win;
 }
Ejemplo n.º 28
0
  public Icon getMoteTypeIcon() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    URL imageURL = this.getClass().getClassLoader().getResource("images/cc430.jpg");
    Image image = toolkit.getImage(imageURL);
    MediaTracker tracker = new MediaTracker(Cooja.getTopParentContainer());
    tracker.addImage(image, 1);
    try {
      tracker.waitForAll();
    } catch (InterruptedException ex) {
    }
    if (image.getHeight(Cooja.getTopParentContainer()) > 0
        && image.getWidth(Cooja.getTopParentContainer()) > 0) {
      image =
          image.getScaledInstance(
              (200
                  * image.getWidth(Cooja.getTopParentContainer())
                  / image.getHeight(Cooja.getTopParentContainer())),
              200,
              Image.SCALE_DEFAULT);
      return new ImageIcon(image);
    }

    return null;
  }
Ejemplo n.º 29
0
 /**
  * Starts loading all images tracked by this media tracker. This method waits until all the images
  * being tracked have finished loading.
  *
  * <p>If there is an error while loading or scaling an image, then that image is considered to
  * have finished loading. Use the <code>isErrorAny</code> or <code>isErrorID</code> methods to
  * check for errors.
  *
  * @see java.awt.MediaTracker#waitForID(int)
  * @see java.awt.MediaTracker#waitForAll(long)
  * @see java.awt.MediaTracker#isErrorAny
  * @see java.awt.MediaTracker#isErrorID
  * @exception InterruptedException if any thread has interrupted this thread
  */
 public void waitForAll() throws InterruptedException {
   waitForAll(0);
 }
Ejemplo n.º 30
0
  public void readJpegImage(URL url, int x, int y, int diskWidth, int diskHeight) {
    Image img = null;
    PixelGrabber pg = null;
    int jpgpix[] = null;
    int i, ret;
    int index;
    boolean results = false;

    byte[] image;
    byte[] realImage;
    DataInputStream gifImage = null;
    int count = 0;

    Toolkit tk = Toolkit.getDefaultToolkit();
    img = tk.getImage(url);

    image = new byte[80 * 1024];
    try {
      gifImage = new DataInputStream(url.openStream());
    } catch (IOException e) {
      System.out.println("readJpegImage error1");
      return;
    }
    try {
      count = gifImage.read(image);
    } catch (IOException e) {
      System.out.println("readJpegImage error2");
    }

    realImage = new byte[count];
    System.arraycopy(image, 0, realImage, 0, count);
    img = tk.createImage(realImage);
    realImage = null;
    count = 0;

    tracker.addImage(img, 0);

    try {
      tracker.waitForAll();
    } catch (InterruptedException e) {
      System.out.println("Error wait for image load");
    }

    jpgpix = new int[diskWidth * diskHeight];
    pg = new PixelGrabber(img, 0, 0, diskWidth, diskHeight, jpgpix, 0, diskWidth);

    try {
      results = pg.grabPixels();
    } catch (InterruptedException e) {
      System.out.println("Grabbing interrupted " + e);
    } catch (Exception e1) {
      System.out.println("General exception grabbing " + e1);
    }

    for (i = 0; i < diskWidth * diskHeight; i++) {
      if (diskHeight == 256) index = 512 * y + x + i / 256 * 512 + i % 256;
      else index = 512 * y + i;
      membuf[index] = jpgpix[i];
      pixel[index] = jpgpix[i]; // added 7/15/99
    }
    tracker.removeImage(img, 0);
    try {
      gifImage.close();
    } catch (IOException e) {
      System.out.println("Can't Close gifImage");
    }
  }