You can use a LookupOp with a four-component LookupTable that sets the alpha component to zero for colors that match the background. Examples may be found in Using the Java 2D LookupOp Filter Class to Process Images and Image processing with Java 2D.