G
grayson
Gast
hallo, ich suche nach einer einfachen möglichkeit ein bild mit einem farbschleier zu belegen bzw in einem bestimmten farbton einzufärben.
public static Image createImage (Image i) {
MyFilter filter = new MyFilter(); // das ist dein Filter
ImageProducer prod = new FilteredImageSource(i.getSource(), filter);
Image image = Toolkit.getDefaultToolkit().createImage(prod);
return image;
}
public void transformColor(Image img){
BufferedImage bi = (BufferedImage)img;
int height=bi.getHeight();
int width = bi.getWidth();
int[] colors= new int[height*width];
DirectColorModel colorModel = (DirectColorModel) ColorModel.getRGBdefault();
for(int i=0;i<height;i++){
for(int a=0;a<width;a++){
int currentRGB= bi.getRGB(i,a);
int red= colorModel.getRed(currentRGB);
int blue= colorModel.getBlue(currentRGB);
int green= colorModel.getGreen(currentRGB);
//... hier muss ich dann noch die gewünschten werte auf 200 setzen
//... und danach natürlich den neuen wert zusammen stellen und mit bi.setRGB(i,a,neuerWert); einfügen
//... k.a. wie das gehn soll ;)
}
}
}
public Image transformColor(Image img, String faction) {
BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
bi.createGraphics().drawImage(img, 0, 0, null);
int height = bi.getHeight();
int width = bi.getWidth();
int[] colors = new int[height * width];
PixelGrabber grabber = new PixelGrabber(img, 0, 0, img.getWidth(null), img.getHeight(null), colors, 0, img.getWidth(null));
try {
grabber.grabPixels();
} catch (Exception e) {
e.printStackTrace();
}
for (int i = 0; i < colors.length; i++) {
System.err.println("ArrayIndex: " + i);
DirectColorModel colorModel = (DirectColorModel) ColorModel.getRGBdefault();
int red = colorModel.getRed(colors[i]);
int blue = colorModel.getBlue(colors[i]);
int green = colorModel.getGreen(colors[i]);
if (faction.trim().equals("marik")) {
red = 200;
blue = 200;
} else if (faction.trim().equals("steiner")) {
blue = 200;
} else if (faction.trim().equals("kurita")) {
red = 200;
} else if (faction.trim().equals("liao")) {
green = 200;
} else if (faction.trim().equals("davion")) {
red = 200;
green = 200;
}
Color result = new Color(red, green, blue);
colors[i] = result.getRGB();
bi.setRGB(0, 0, width, height, colors, 0, width * height */was dieser parameter bedeuten soll.... k.a.
laut javadoc steht da "@param scansize the scanline stride" ----> was is los? /*);
}
return bi;
}
bi = ImageIO.read( new File( FILENAME) );
for ( int i = 0; i < bi.getWidth(); i++ ) {
for ( int j = 0; j < bi.getHeight(); j++ ) {
int rgb = bi.getRGB(i, j);
Color c = new Color(rgb);
int newRGB = new Color( c.getRed(), c.getGreen(), 200 ).getRGB();
bi.setRGB(i, j, newRGB);
}
}
grayson hat gesagt.:hey sky, danke für deinen tipp, damit geht es, bis auf einen hässlichen schwarzen rand (die bereiche die transparent sein sollen.....) hast noch ne ahnung wie ich das auch noch hin bekomm?