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,

[333 byte] By [KillerScapea] at [2007-11-27 6:00:45]
# 1
Follow this path in your sdksdk1.5/src/com/sun/java/swing/plaf/windows/XPStyleand look for the convertToTransparent method.
crwooda at 2007-7-12 16:39:21 > top of Java-index,Security,Cryptography...
# 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,

KillerScapea at 2007-7-12 16:39:21 > top of Java-index,Security,Cryptography...
# 3

symbol : method grabPixels()

location: class java.awt.image.BufferedImage

imgt.grabPixels();

The compiler is saying that the class BufferedImage does not have a method named

grabPixels. The PixelGrabber class does have such a method. Perhaps you meant to write

pixelGrabber.grabPixels();

Call the method on the instance of the PixelGrabber instead of on the instance of the

BufferedImage (imgt).

crwooda at 2007-7-12 16:39:21 > top of Java-index,Security,Cryptography...