Reputation: 13
I have my main;
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);
}
}
then I have my class;
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;
}
}
Both of which works fine, but then I try to write my own class;
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;
}
}
I get two errors, one for my main;
filters[1] = new BlueFilter("Blue Filter");
"Type mismatch: cannot convert from BlueFilter to ImageFilter"
and one for the class I'm trying to add, in the constructor;
public BlueFilter(String name) {
super(name);
}
"The constructor ImageFilter(String) is undefined"
I am lost here, what is the problem? I pretty much copied IdentityFilter, which worked fine, yet it does not work. Any help is greatly appreciated. I'm a beginner, so please keep explain whatever I'm doing wrong.
Here is the superclass if anyone needs it, I have not written it;
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);
}
}
Upvotes: 0
Views: 162
Reputation: 2773
You are importing java.awt.image.ImageFilter;
instead of se.lth.cs.ptdc.images.ImageFilter;
.
Upvotes: 5