public SeamCarver(Picture picture) {
    // create a seam carver object based on the given picture
    int picWidth = picture.width();
    int picHeight = picture.height();
    currentPicture = picture;
    pixelColor = new Color[picWidth][picHeight];

    for (int i = 0; i < picHeight; i++) {
      for (int j = 0; j < picWidth; j++) {
        pixelColor[j][i] = picture.get(j, i);
      }
    }
  }
Exemple #2
0
  private Picture initialImage() {
    pic2 = new Picture(500, 600);
    pic1 = new Picture(500, 600);

    for (int x = 0; x < pic2.width(); x++)
      for (int y = 0; y < pic2.height(); y++) {
        double dist = 1.0 - Math.sqrt((x - 300) * (x - 300) + (y - 200) * (y - 200)) / 500;
        int red =
            (int)
                (dist < 0.5
                    ? 0
                    : Math.min(Math.pow(dist, 0.4) + Math.pow(dist - 0.5, 0.1), 1.0) * 255);
        int green = (int) (dist * 255);
        int blue = 0;
        pic2.set(x, y, new Color(red, green, blue));
      }
    return pic2;
  }
Exemple #3
0
  public void actionPerformed(ActionEvent e) {
    String cmd = (e.getActionCommand());

    if (cmd.equals(aboutItem.getText()))
      JOptionPane.showMessageDialog(
          this,
          "Simple Image Program for DB2004\nversion 0.1\nThanks to BvS",
          "About imageLab",
          JOptionPane.INFORMATION_MESSAGE);
    else if (cmd.equals(quitItem.getText())) System.exit(0);
    else if (cmd.equals(openItem.getText())) {
      int returnVal = chooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          pic2 = new Picture(chooser.getSelectedFile().getName());
          pic1 = new Picture(pic2.width(), pic2.height());
          lab.setIcon(pic2.getJLabel().getIcon());
          sliderPanel.setVisible(false);
          pack();
          repaint();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this,
              "Could not open " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(),
              "Open Error",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }

    } else if (cmd.equals(saveItem.getText())) {
      int returnVal = chooser.showSaveDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          pic2.save(chooser.getSelectedFile().getName());
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this,
              "Could not write " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(),
              "Save Error",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }
    }
  }
 public int width() {
   // width of current picture
   return currentPicture.width();
 }