0
저는 메인을 가지고 있습니다.수퍼 클래스 생성자가 정의되지 않았습니다.
package lab8_9;
import se.lth.cs.ptdc.images.ImageFilter;
import se.lth.cs.ptdc.images.ImageGUI;
public class ImageProcessor {
public static void main(String[] args) {
ImageFilter[] filters = new ImageFilter[2];
filters[0] = new IdentityFilter("Identity Filter");
filters[1] = new BlueFilter("Blue Filter");
new ImageGUI(filters);
}
}
나는 수업을 진행합니다.
package lab8_9;
import java.awt.Color;
import se.lth.cs.ptdc.images.ImageFilter;
public class IdentityFilter extends ImageFilter {
public IdentityFilter(String name) {
super(name);
}
public Color[][] apply(Color[][] inPixels, double paramValue) {
int height = inPixels.length;
int width = inPixels[0].length;
Color[][] outPixels = new Color[height][width];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
Color pixel = inPixels[i][j];
outPixels[i][j] = new Color(pixel.getRed(),
pixel.getGreen(),
pixel.getBlue());
}
}
return outPixels;
}
}
두 가지 모두 정상적으로 작동하지만 내 자신의 클래스를 작성하려고합니다.
package lab8_9;
import java.awt.Color;
import java.awt.image.ImageFilter;
public class BlueFilter extends ImageFilter {
public BlueFilter(String name) {
super(name);
}
public Color[][] apply(Color[][] inPixels, double paramValue) {
int height = inPixels.length;
int width = inPixels[0].length;
Color[][] outPixels = new Color[height][width];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
Color pixel = inPixels[i][j];
outPixels[i][j] = new Color(0,
0,
pixel.getBlue());
}
}
return outPixels;
}
}
두 개의 오류가 발생합니다.
filters[1] = new BlueFilter("Blue Filter");
: 생성자에서,
내가 추가 할 노력하고있어 클래스를 "형식 불일치이며, ImageFilter하는 BlueFilter에서 변환 할 수 없습니다";
public BlueFilter(String name) {
super(name);
}
여기 분실하고
을 "생성자이며, ImageFilter (문자열) 정의되지 않는다"문제는 무엇인가? IdentityFilter는 꽤 잘 복사되었지만 작동하지 않습니다. 어떤 도움이라도 대단히 감사합니다. 나는 초보자이기 때문에 내가 뭘 잘못했는지 설명 해주십시오.
누군가가 그것을 필요로한다면 여기에 슈퍼 클래스가 있습니다. 나는 그것을 작성하지 않았습니다;
package se.lth.cs.ptdc.images;
import java.awt.Color;
public abstract class ImageFilter {
private String name;
protected ImageFilter(String name) {
this.name = name;
}
public String getName() {
return name;
}
public abstract Color[][] apply(Color[][] inPixels, double paramValue);
protected short[][] computeIntensity(Color[][] pixels) {
int height = pixels.length;
int width = pixels[0].length;
short[][] intensity = new short[height][width];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
Color c = pixels[i][j];
intensity[i][j] = (short) ((c.getRed() + c.getGreen() + c
.getBlue())/3);
}
}
return intensity;
}
protected short convolve(short[][] p, int i, int j, short[][] kernel,
int weight) {
short sum = 0;
for (int ii = -1; ii <= 1; ii++) {
for (int jj = -1; jj <= 1; jj++) {
sum += p[i + ii][j + jj] * kernel[ii + 1][jj + 1];
}
}
return (short) Math.round((double) sum/weight);
}
}
오 와우, 매우 빠른 대답이었습니다. :), 감사합니다. 이제는 내 프로그램이 잘 작동합니다! – BarksRosaRota