Make pixelgrabber ignore certain colored pixels.
Hi,
I am trying to load images with a transparent background and have worked out that to do it i need to make my program ignore certain pixels (for example i could make the bit i don't want bright orange) i would then max pixelgrabber ignore all bright orange pixels.
Does anyone know how to do this?
James,
# 2
Hi, I have been looking around and have changed the code to this:
try
{
BufferedImage img = ImageIO.read(new File(spritepath+"/"+s+" "+i+".png"));
// Fade image with AlphaComposite.
BufferedImage imgt = setTransparency(img, Color.BLACK);
// Make all black pixels transparent.
//Image image = Toolkit.getDefaultToolkit().getImage(spritepath+"/"+s+" "+i+".png");//System.getProperty("user.dir") + "\\"+i+".png");
anIntArray1439 = new int[anInt1440 * anInt1441];
//PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, anInt1440, anInt1441, anIntArray1439, 0, anInt1440);
//BufferedImage.drawImage(imgt, 0, 0, null);
imgt.grabPixels();
//System.out.println(s+" "+i+".png"+ " hopefully loaded");
}
catch (Exception exception)
{
System.out.println(((Object) (exception)));
}
}
I then have the following:
public static BufferedImage createBufferedImage(Image image) {
if(image instanceof BufferedImage)
return (BufferedImage)image;
int w = image.getWidth(null);
int h = image.getHeight(null);
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
/*Graphics2D g = bi.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();*/
return bi;
}
public static BufferedImage setTransparency(Image src, Color transparency) {
int width = src.getWidth(null);
int height = src.getHeight(null);
BufferedImage dst = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = dst.createGraphics();
g.setColor(transparency);
// zero alpha value is 100% transparency (invisible), try alpha > 0
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f));
g.drawRenderedImage(createBufferedImage(src), null);
g.dispose();
return dst;
}
When i try to compile it i get:
Class30_Sub2_Sub1_Sub1.java:266: cannot find symbol
symbol : method grabPixels()
location: class java.awt.image.BufferedImage
imgt.grabPixels();
^
Any help!
James,