0
我的提示是:制作幻灯片JAVA
编写一个程序,它的多个图像文件作为命令行参数的名称,并将其显示在幻灯片(一个每两秒钟),使用褪色效果到黑色和图片之间的黑色淡化。
我有变淡的图像,但我有,保持在一个窗口中的所有图像有问题的部分。例如,当我运行我的程序时,它会打开一个新窗口 - 将图片A淡入黑色图片。用黑色图像打开一个新窗口,然后淡入图片c。我试图让它从图片A开始,淡入黑色,然后在不打开新窗口的情况下淡入新图片。我知道它与我的pic.show()代码有关,但我不知道如何解决这个问题。
这里是我的代码:
package fade;
import edu.princeton.cs.introcs.Picture;
import java.awt.Color;
public class Fade {
public static Color blend(Color c, Color d, double alpha) {
double r = (1 - alpha) * c.getRed() + alpha * d.getRed();
double g = (1 - alpha) * c.getGreen() + alpha * d.getGreen();
double b = (1 - alpha) * c.getBlue() + alpha * d.getBlue();
return new Color((int) r, (int) g, (int) b);
}
public static void pause(int t) {
try { Thread.sleep(t); }
catch (InterruptedException e) { System.out.println("Error sleeping"); }
}
public static void main(String[] args) {
for (int k = 1; k < args.length; k++) {
Picture source = new Picture(args[k]);
Picture target = new Picture(args[0]);
int M = 100;
int width = source.width();
int height = source.height();
Picture pic = new Picture(width, height);
for (int t = 0; t <= M; t++) {
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
Color c0 = source.get(i, j);
Color cM = target.get(i, j);
Color c = blend(c0, cM, (double) t/M);
pic.set(i, j, c);
}
}
pic.show();
}
}
}
}
查看http://introcs.cs.princeton.edu/java/stdlib/Picture.java.html这只是Picture类的行为。它调用'show'时为每个实例打开一个新窗口(JFrame)。你必须改变你的方法... – home 2013-02-16 21:37:30
任何想法如何解决这个问题的不同? – 2013-02-16 22:19:43
对不起,我不知道这个API – home 2013-02-16 22:43:37