예제 #1
0
  private void scaleImage() {
    width = image.getWidth(this);
    height = image.getHeight(this);
    double ratio = 1.0;

    /*
     * Determine how to scale the image. Since the accessory can expand
     * vertically make sure we don't go larger than 150 when scaling
     * vertically.
     */
    if (width >= height) {
      ratio = (double) (ACCSIZE - 5) / width;
      width = ACCSIZE - 5;
      height = (int) (height * ratio);
    } else {
      if (getHeight() > 150) {
        ratio = (double) (ACCSIZE - 5) / height;
        height = ACCSIZE - 5;
        width = (int) (width * ratio);
      } else {
        ratio = (double) getHeight() / height;
        height = getHeight();
        width = (int) (width * ratio);
      }
    }

    image = image.getScaledInstance(width, height, Image.SCALE_DEFAULT);
  }
  public void zoomIn() {
    Dimension asz = this.getSize();
    int maxzf = 3;
    int coef = 1;
    int r;

    cmdline =
        "/bin/sh get.sh "
            + j2kfilename
            + " "
            + iw
            + " "
            + ih
            + " "
            + rect.x
            + " "
            + rect.y
            + " "
            + rect.width
            + " "
            + rect.height;
    Exec.execPrint(cmdline);

    rect.x = rect.y = rect.width = rect.height = 0;

    img = pgm.open("out.pgm");

    iw = img.getWidth(this);
    ih = img.getHeight(this);
    bi = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
    big = bi.createGraphics();
    selected = 0;
    fullRefresh = true;
    repaint();
  }
예제 #3
0
 // buffered images are just better.
 protected static BufferedImage imageToBufferedImage(Image img) {
   BufferedImage bi =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = bi.createGraphics();
   g2.drawImage(img, null, null);
   return bi;
 }
예제 #4
0
 private static Image getImage(ResizableIcon icon, int size) {
   icon.setDimension(new Dimension(size, size));
   if (icon instanceof AsynchronousLoading) {
     AsynchronousLoading async = (AsynchronousLoading) icon;
     if (async.isLoading()) {
       final CountDownLatch latch = new CountDownLatch(1);
       final boolean[] status = new boolean[1];
       AsynchronousLoadListener all =
           new AsynchronousLoadListener() {
             @Override
             public void completed(boolean success) {
               status[0] = success;
               latch.countDown();
             }
           };
       async.addAsynchronousLoadListener(all);
       try {
         latch.await();
       } catch (InterruptedException ignored) {
       }
       async.removeAsynchronousLoadListener(all);
       if (!status[0]) {
         return null;
       }
       if (async.isLoading()) {
         return null;
       }
     }
   }
   Image result = FlamingoUtilities.getBlankImage(size, size);
   Graphics2D g2d = (Graphics2D) result.getGraphics().create();
   icon.paintIcon(null, g2d, 0, 0);
   g2d.dispose();
   return result;
 }
예제 #5
0
  public void paint(Graphics gg) {
    int faceSize = Math.min(getWidth() - 4, getHeight() - 4);
    if (face == null)
      face =
          new PADFaceMapped(
              Math.max(2, (getWidth() - faceSize) / 2),
              Math.max(2, (getHeight() - faceSize) / 2),
              faceSize);
    if (buffer == null) {
      im = this.createImage(getWidth(), getHeight());
      buffer = im.getGraphics();
    }
    super.paint(buffer);

    buffer.setColor(new Color(255, 255, 255, 0));
    buffer.fillRect(0, 0, im.getWidth(null), im.getHeight(null));

    face.setDimensions(
        Math.max(2, (getWidth() - faceSize) / 2),
        Math.max(2, (getHeight() - faceSize) / 2),
        faceSize);
    face.paint(buffer);

    // draw buffer to screen
    gg.drawImage(im, 0, 0, null, null);
  }
  public static void saveJPG(Image img, String s) {
    BufferedImage bi =
        new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = bi.createGraphics();
    g2.drawImage(img, null, null);

    FileOutputStream out = null;
    try {
      out = new FileOutputStream(s);
    } catch (java.io.FileNotFoundException io) {
      System.out.println("File Not Found");
    }

    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
    param.setQuality(0.5f, false);
    encoder.setJPEGEncodeParam(param);

    try {
      encoder.encode(bi);
      out.close();
    } catch (java.io.IOException io) {
      System.out.println("IOException");
    }
  }
예제 #7
0
  /**
   * Returns the specified image as icon.
   *
   * @param name name of icon
   * @return icon
   */
  public static ImageIcon icon(final String name) {
    ImageIcon ii = ICONS.get(name);
    if (ii != null) return ii;

    Image img;
    if (GUIConstants.scale > 1) {
      // choose large image or none
      final URL url =
          GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null;

      if (url == null) {
        // resize low-res image if no hi-res image exists
        img = get(url(name));
        final int w = (int) (img.getWidth(null) * GUIConstants.scale);
        final int h = (int) (img.getHeight(null) * GUIConstants.scale);
        final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        final Graphics2D g2 = tmp.createGraphics();
        g2.setRenderingHint(
            RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2.drawImage(img, 0, 0, w, h, null);
        g2.dispose();
        img = tmp;
      } else {
        img = get(url);
      }
    } else {
      img = get(name);
    }
    ii = new ImageIcon(img);
    ICONS.put(name, ii);
    return ii;
  }
예제 #8
0
  // CONSTRUCTOR
  public DrawRooms(int[][] arooms) {
    try {
      image1 = ImageIO.read(new File("tiger.gif"));
      image2 = ImageIO.read(new File("prisoner.gif"));
      image3 = ImageIO.read(new File("princess.jpg"));

    } catch (IOException e) {;
    }
    //		 Image image;

    // THIS WILL ASSIGN A REFERENCE TO ARRAY OF INTS CREATED  IN GUI CLASS
    this.Arooms = arooms;

    // YOU NEED TO SET THE PREFERRED SIZE TO GET THE DISPLAY THE SIZE YOU WANT IT.
    setPreferredSize(new Dimension(620, 620));

    //	  CREATE  THREE  IMAGEICONS E.G. THIS SHOWs HOW TO SCALE IT

    // create the imageicon
    // get an image object from it
    image1 = image1.getScaledInstance(28, 28, Image.SCALE_SMOOTH); // reduce its size
    image2 = image2.getScaledInstance(28, 28, Image.SCALE_SMOOTH); // reduce its size
    image3 = image3.getScaledInstance(28, 28, Image.SCALE_SMOOTH); // reduce its size

    //

    //       setBackground(Color.yellow);

  }
예제 #9
0
  private void drawWeaponTokenForRoom(
      Graphics g, Board board, Room room, double centreX, double topY, double step) {
    Weapon weapon = _weaponLocations.get(room);

    if (weapon != null) {
      Image weaponTokenImage = weapon.tokenImage();

      double weaponTokenWidth = weaponTokenImage.getWidth(null);
      double weaponTokenHeight = weaponTokenImage.getHeight(null);

      double longestSideLength = step * WeaponTokenRatio;

      // scale so that the longest side is always larger
      if (weaponTokenWidth >= weaponTokenHeight) {
        weaponTokenWidth = longestSideLength;
        double ratio = weaponTokenImage.getWidth(null) / weaponTokenWidth;
        weaponTokenHeight = weaponTokenHeight / ratio;
      } else {
        weaponTokenHeight = longestSideLength;
        double ratio = weaponTokenImage.getHeight(null) / weaponTokenHeight;
        weaponTokenWidth = weaponTokenWidth / ratio;
      }

      g.drawImage(
          weaponTokenImage,
          (int) (centreX - weaponTokenWidth / 2),
          (int) (topY),
          (int) weaponTokenWidth,
          (int) weaponTokenHeight,
          null);
    }
  }
예제 #10
0
    private BufferedImage getAppImage() {
      assertIsDispatchThread();

      try {
        if (myAppImage != null) return myAppImage;

        Object app = getApp();
        Image appImage = (Image) getAppMethod("getDockIconImage").invoke(app);

        if (appImage == null) return null;

        int width = appImage.getWidth(null);
        int height = appImage.getHeight(null);
        BufferedImage img = UIUtil.createImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = img.createGraphics();
        g2d.drawImage(appImage, null, null);
        myAppImage = img;
      } catch (NoSuchMethodException e) {
        return null;
      } catch (Exception e) {
        LOG.error(e);
      }

      return myAppImage;
    }
예제 #11
0
  /**
   * Create a splash screen (borderless graphic for display while other operations are taking
   * place).
   *
   * @param filename a class-relative path to the splash graphic
   * @param callingClass the class to which the graphic filename location is relative
   */
  public SplashScreen(String filename, Class callingClass) {
    super(new Frame());
    URL imageURL = callingClass.getResource(filename);
    image = Toolkit.getDefaultToolkit().createImage(imageURL);
    // Load the image
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 0);
    try {
      mt.waitForID(0);
    } catch (InterruptedException ie) {
    }

    // Center the window on the screen
    int imgWidth = image.getWidth(this);
    int imgHeight = image.getHeight(this);
    setSize(imgWidth, imgHeight);
    Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((screenDim.width - imgWidth) / 2, (screenDim.height - imgHeight) / 2);

    setVisible(true);
    repaint();
    // if on a single processor machine, wait for painting (see Fast Java Splash Screen.pdf)
    if (!EventQueue.isDispatchThread()) {
      synchronized (this) {
        while (!this.paintCalled) {
          try {
            this.wait();
          } catch (InterruptedException e) {
          }
        }
      }
    }
  }
예제 #12
0
  /*
   * Frame Constructor
   */
  public EvalGUI() {

    // map image

    Image img = null;
    try {
      img = ImageIO.read(new File("map2.png"));
    } catch (IOException e) {
    }

    img = img.getScaledInstance(300, 300, Image.SCALE_SMOOTH);

    JLabel small_img = new JLabel(new ImageIcon(img));

    getContentPane().setLayout(new BorderLayout());

    Right_Panel.add(Statistics_Panel, BorderLayout.CENTER);

    Statistics_Panel.add(dist_title);
    Statistics_Panel.add(totaldistance);
    Statistics_Panel.add(dist_curr_obj);
    Statistics_Panel.add(dist_charge);
    Statistics_Panel.add(clean_title);
    Statistics_Panel.add(space_covered);
    Statistics_Panel.add(room_covered);
    Statistics_Panel.add(charge_visits);
    Statistics_Panel.add(battery_title);
    Statistics_Panel.add(batt_remaining);
    Statistics_Panel.add(coverage_title);
    Statistics_Panel.add(nr_coverage_divisions);
    Statistics_Panel.add(vert_hor_div);
    Statistics_Panel.add(rob_coord);
    Statistics_Panel.add(time_elapsed);
    Statistics_Panel.add(time_completion);
    Right_Panel.add(small_img, BorderLayout.SOUTH);

    add(Right_Panel, BorderLayout.EAST);
    add(Map_Panel, BorderLayout.WEST);

    // menu items
    menubar.add(file);
    menubar.add(options);
    menubar.add(exit);
    file.add(newmap);
    options.add(measure);
    options.add(speed);
    exit.add(exit_);
    setJMenuBar(menubar);

    // frame operations
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(860, 650);
    setTitle("EvaluationGUI");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // pack();

  }
예제 #13
0
 // set size of the button (inherited from JButton =) )
 // changes the size of the button, and resizes the image to fit it.
 public void setSize(int x, int y) {
   if (!mode.equals("String")) {
     width = x;
     height = x;
     image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
     BWimage = BWimage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
   }
 }
예제 #14
0
 private void scaleImage() {
   Image img =
       back.getScaledInstance(scx(back.getWidth()), scy(back.getHeight()), Image.SCALE_SMOOTH);
   back =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   Graphics g = back.getGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
 }
예제 #15
0
 @Override
 public final void destroyBuffers() {
   final Image oldBB = getBackBuffer();
   synchronized (getStateLock()) {
     backBuffer = null;
   }
   if (oldBB != null) {
     oldBB.flush();
   }
 }
예제 #16
0
 public static BufferedImage fetchFromURL(URL url) {
   Image i = new ImageIcon(url).getImage();
   if (i.getWidth(null) <= 0 || i.getHeight(null) <= 0) {
     CrimsonLog.warning("BAD IMAGE! (%s)", url);
     return null;
   }
   BufferedImage bi =
       new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   bi.getGraphics().drawImage(i, 0, 0, null);
   return bi;
 }
    public void paint(Graphics g) {
      super.paint(g);

      if (myResizable && myDrawMacCorner) {
        g.drawImage(
            ourMacCorner,
            getX() + getWidth() - ourMacCorner.getWidth(this),
            getY() + getHeight() - ourMacCorner.getHeight(this),
            this);
      }
    }
 public void update(Graphics g) {
   Graphics gr;
   if (offScreenBuffer == null
       || (!(offScreenBuffer.getWidth(this) == this.size().width
           && offScreenBuffer.getHeight(this) == this.size().height))) {
     offScreenBuffer = this.createImage(size().width, size().height);
   }
   gr = offScreenBuffer.getGraphics();
   paint(gr);
   g.drawImage(offScreenBuffer, 0, 0, this);
 }
예제 #19
0
 private static ImageIcon makeGrayImageIcon1(Image img) {
   BufferedImage source =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   Graphics g = source.createGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
   ColorConvertOp colorConvert =
       new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
   BufferedImage destination = colorConvert.filter(source, null);
   return new ImageIcon(destination);
 }
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (image != null) {
     g.drawImage(
         image,
         (this.getWidth() / 2) - (image.getWidth(this) / 2),
         (this.getHeight() / 2) - (image.getHeight(this) / 2),
         image.getWidth(this),
         image.getHeight(this),
         this);
   }
 }
예제 #21
0
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y).
   *
   * @param x the center x-coordinate of the image
   * @param y the center y-coordinate of the image
   * @param s the name of the image/picture, e.g., "ball.gif"
   * @throws RuntimeException if the image is corrupt
   */
  public static void picture(double x, double y, String s) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    int ws = image.getWidth(null);
    int hs = image.getHeight(null);
    if (ws < 0 || hs < 0) throw new RuntimeException("image " + s + " is corrupt");

    offscreen.drawImage(
        image, (int) Math.round(xs - ws / 2.0), (int) Math.round(ys - hs / 2.0), null);
    draw();
  }
예제 #22
0
 private static ImageIcon makeGrayImageIcon2(Image img) {
   int w = img.getWidth(null);
   int h = img.getHeight(null);
   BufferedImage destination = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
   Graphics g = destination.createGraphics();
   //// g.setColor(Color.WHITE);
   // https://community.oracle.com/thread/1373262 Color to Grayscale to Binary
   // g.fillRect(0, 0, w, h); // need to pre-fill(alpha?)
   g.drawImage(img, 0, 0, null);
   g.dispose();
   return new ImageIcon(destination);
 }
  /**
   * The image we're replacing.
   *
   * @return see desc
   */
  public Image getImage() {
    if (!_loaded && _imageResource.isLoaded()) {
      Image image = ((AWTFSImage) _imageResource.getImage()).getImage();
      if (_doScaleImage && (_targetWidth > 0 || _targetHeight > 0)) {
        int w = image.getWidth(null);
        int h = image.getHeight(null);
        int newW = _targetWidth;
        int newH = _targetHeight;

        if (newW == -1) {
          newW = (int) (w * ((double) newH / h));
        }

        if (newH == -1) {
          newH = (int) (h * ((double) newW / w));
        }

        if (w != newW || h != newH) {
          if (image instanceof BufferedImage) {
            image = ImageUtil.getScaledInstance((BufferedImage) image, newW, newH);
          } else {
            if (true) {
              throw new RuntimeException(
                  "image is not a buffered image! " + _imageResource.getImageUri());
            }
            String scalingType = Configuration.valueFor("xr.image.scale", "HIGH").trim();

            if (scalingType.equalsIgnoreCase("HIGH") || scalingType.equalsIgnoreCase("MID")) {
              image = image.getScaledInstance(newW, newH, Image.SCALE_SMOOTH);
            } else {
              image = image.getScaledInstance(newW, newH, Image.SCALE_FAST);
            }
          }
        }
        _image = image;
      } else {
        _image = image;
      }
      _loaded = true;
      XRLog.load(
          Level.FINE,
          "Icon: replaced image " + _imageResource.getImageUri() + ", repaint requested");
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              repaintListener.repaintRequested(_doScaleImage);
            }
          });
    }

    return _image;
  }
예제 #24
0
  public void resize() {

    height = (height == 0) ? 1 : height;

    ratio = (double) image.getIconWidth() / image.getIconHeight();

    Image img = image.getImage();
    width = width - 10;
    // 4 = Image.SCALE_SMOOTH
    Image newimg = img.getScaledInstance(width, (int) (width / ratio), 4);

    label1.setIcon(new ImageIcon(newimg));
  }
예제 #25
0
  private void displayImage(Image image) {
    if (DEBUG.RESOURCE || DEBUG.IMAGE) out("displayImage " + Util.tag(image));

    mImage = image;
    if (mImage != null) {
      mImageWidth = mImage.getWidth(null);
      mImageHeight = mImage.getHeight(null);
      if (DEBUG.IMAGE) out("displayImage " + mImageWidth + "x" + mImageHeight);
    }

    clearStatus();
    repaint();
  }
예제 #26
0
 @NotNull
 private static Image scaleImage(Image image, float scale) {
   int w = image.getWidth(null);
   int h = image.getHeight(null);
   if (w <= 0 || h <= 0) {
     return image;
   }
   int width = (int) (scale * w);
   int height = (int) (scale * h);
   // Using "QUALITY" instead of "ULTRA_QUALITY" results in images that are less blurry
   // because ultra quality performs a few more passes when scaling, which introduces blurriness
   // when the scaling factor is relatively small (i.e. <= 3.0f) -- which is the case here.
   return Scalr.resize(ImageUtil.toBufferedImage(image), Scalr.Method.QUALITY, width, height);
 }
  @Override
  public void paint(Graphics g) {
    super.paintComponent(g);
    Image img = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics image = img.getGraphics();

    for (Obstacle obstacle : obstacles) {
      paintObstacle(image, obstacle);
    }

    paintMobileRobot(image);

    g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), SystemColor.window, null);
  }
예제 #28
0
  public Dimension getPreferredSize() {
    int w, h;
    Dimension result;

    if (image == null) {
      result = new Dimension(0, 0);
    } else {
      w = image.getWidth(null);
      h = image.getHeight(null);
      result = new Dimension(w > 0 ? w : 0, h > 0 ? h : 0);
    }

    return result;
  }
예제 #29
0
 /**
  * Gets a buffered image.
  *
  * @return the image
  */
 public BufferedImage getBufferedImage() {
   if (image == null && isAnImage) {
     Image im = getImage();
     if (im == null) {
       isAnImage = false;
     } else {
       image =
           new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_INT_RGB);
       Graphics2D g2 = image.createGraphics();
       g2.drawImage(im, 0, 0, null);
     }
   }
   return image;
 }
예제 #30
0
  public void drawRocket(
      Image image, int xpos, int ypos, double rot, double xscale, double yscale) {
    int width = rocketImage.getWidth(this);
    int height = rocketImage.getHeight(this);
    g.translate(xpos, ypos);
    g.rotate(rot * Math.PI / 180.0);
    g.scale(xscale, yscale);

    g.drawImage(image, -width / 2, -height / 2, width, height, this);

    g.scale(1.0 / xscale, 1.0 / yscale);
    g.rotate(-rot * Math.PI / 180.0);
    g.translate(-xpos, -ypos);
  }