All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.apiclub.captcha.backgrounds.TransparentBackgroundProducer Maven / Gradle / Ivy

The newest version!
package cn.apiclub.captcha.backgrounds;

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

/**
 * Generates a transparent background.
 * 
 * @author James Childers
 *
 */
public class TransparentBackgroundProducer implements BackgroundProducer {

	@Override
	public BufferedImage addBackground(BufferedImage image) {
		return getBackground(image.getWidth(), image.getHeight());
	}

	@Override
	public BufferedImage getBackground(int width, int height) {
		BufferedImage bg = new BufferedImage(width, height, BufferedImage.TRANSLUCENT);
		Graphics2D g = bg.createGraphics();

		g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
		g.fillRect(0, 0, width, height);
		
		return bg;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy