0

我创建了一个在picture.java 中运行的方法。在我的 Main Method 中调用该方法后,运行它后什么都没有显示。

它应该拍摄一张图片(由 xMin、xMax、yMin、yMax 又名矩形/正方形指定)并根据 1)其当前颜色值和 2)更改像素的颜色我们输入的双倍值

这是我的代码:

import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.text.*;
import java.util.*;
import java.util.List;

// resolves problem with java.awt.List and java.util.List

/**
 * A class that represents a picture.  This class inherits from 
 * SimplePicture and allows the student to add functionality to
 * the Picture class.  
 * 
 * Copyright Georgia Institute of Technology 2004-2005
 * @author Barbara Ericson ericson@cc.gatech.edu
 */
public class Picture extends SimplePicture 
{
///////////////////// constructors //////////////////////////////////

/**
 * Constructor that takes no arguments 
 */
public Picture ()
{
  /* not needed but use it to show students the implicit call to super()
   * child constructors always call a parent constructor 
   */
  super();  
}

/**
 * Constructor that takes a file name and creates the picture 
 * @param fileName the name of the file to create the picture from
 */
public Picture(String fileName)
{
  // let the parent class handle this fileName
  super(fileName);
}

/**
 * Constructor that takes the width and height
 * @param width the width of the desired picture
 * @param height the height of the desired picture
 */
public Picture(int width, int height)
{
  // let the parent class handle this width and height
  super(width,height);
}

/**
 * Constructor that takes a picture and creates a 
 * copy of that picture
 */
public Picture(Picture copyPicture)
{
  // let the parent class do the copy
  super(copyPicture);
}

/**
 * Constructor that takes a buffered image
 * @param image the buffered image to use
 */
public Picture(BufferedImage image)
{
  super(image);
}

////////////////////// methods ///////////////////////////////////////


public class boolean manipulateBox(int xMin, int yMin, int xMax, int yMax, double amount)
{

Pixel pixel = null;
int x;
int y;
int value;
int amount2;

y = yMin;
while(y <= yMax)
{
  x = xMin;
  while(x <= xMax)
  {
    pixel = this.getPixel(x,y);

    amount2 = ((int)(amount));

    value = pixel.getBlue();

    pixel.setBlue(amount2 * value);
  }
  x = x + 1;
}
y = y + 1;
return true; 
}

public static void main(String[] args) 
{
   String fileName = FileChooser.pickAFile();
   Picture pictObj = new Picture(fileName);
   pictObj.manipulateBox(50,50,100,100,0.5);
   pictObj.explore();
 }
4

1 回答 1

1

x = x + 1;

必须在 x < xMax while 循环内

与您的 y 变量相同

否则,它将创建一个无限循环,从而导致冻结

我知道这是一个很晚的回应,所以这是给谷歌人阅读的:)

于 2013-09-24T21:49:22.897 回答