transparency filter
I lack software that lets me save images with transparency in them, so I have to code something that will give my images transparency. Currently what I'm doing is having the part of the image i want transparent to be magenta, then I have a code that changes all magenta pixels into transparent ones. Here's the code I did:
public Image filter(Image img){
BufferedImage b =new BufferedImage(img.getWidth(null),img.getHeight(null),BufferedImage.TYPE_INT_ARGB);
int filt =new Color(255,0,255).getRGB();
int repl =new Color(255,255,255,0).getRGB();
b.createGraphics().drawImage(img,0,0,null);
for (int y = 0;y < b.getHeight();y++){
for (int x = 0;x < b.getWidth();x++){
if (b.getRGB(x,y) == filt){
b.setRGB(x,y,repl);
}
}
}
return createImage(b.getSource());
}
..this code works great, but just a tad slow. I remember seeing somewhere that someone used a different class to achieve this easier. Does anyone know what it is? If not, is there an easier way to do this?
Many thanks. :E
[1799 byte] By [
Woogleya] at [2007-9-28 19:17:20]

MS Paint (for Windows 2000 don't know about others, don't use) does support transparency.
Save the file as a GIF, then in
Image -> Attributes ( Ctrl-E )
use the "Transparency" & Select a colour for transparency.
Then download [url=http://catb.org/~esr/gif2png/]gif2png[/url]
then [url=http://pmt.sourceforge.net/pngcrush/]pngcrush[/url]
Or, if you have a lesser version of paint, download [url=http://pmt.sourceforge.net/bmp2png/]bmp2png[/url]
convert bmp to png, open in Microsoft Photo Editor, use the "Select Transparency Colour" toolbar button, click on the colour you want transparent, save, [url=http://pmt.sourceforge.net/pngcrush/]pngcrush[/url].
Or finally write a quick Java app, I'm guessing untested, save as png/gif (using on of the methods above) then:
import java.net.*;
import java.io.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class Test {
public void main(String argv[] ){
try {
OutputStream outputStream = FileOutputStream( argv[1] );
URL url = new URL( argv[0] );
InputStream is = url.openStream();
BufferedImage bimg = ImageIO.read( is );
for( int x = 0; y < getHeight(); x ++ ) {
for( int y = 0; y < getWidth(); y ++ ) {
if( bimg.getRGB(x, y ) == 0xFFFFFF ) { // White pix
bimg.setRGB( x, y, 0xFFFFFFFF ); // white,
// full aplha
}
}
}
ImageIO.write(bimg , "png", outputStream);
}catch(Throwable t) {
System.err.println( t );
}
}
}
All the paint applications you need.
mlka at 2007-7-12 17:46:33 >

Well, I think I have something like that in GAGE... (ducks)
Seriously tho, go get GIMP:
http://www.gimp.org
This one (free!) download will give you the power to create just about any image format known to mankind. It will also give you all kinds of filters and image tools similar to the ones found in Photoshop. Trust me, it's worth the download.