TransparentBackgroundProducer.java :  » J2EE » SimpleCaptcha-1.1.1 » nl » captcha » backgrounds » Java Open Source

Java Open Source » J2EE » SimpleCaptcha 1.1.1 
SimpleCaptcha 1.1.1 » nl » captcha » backgrounds » TransparentBackgroundProducer.java
package nl.captcha.backgrounds;

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

/**
 * Generates a transparent background.
 * 
 * @author <a href="mailto:james.childers@gmail.com">James Childers</a>
 *
 */
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;
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.