package rpgEngine.Util;

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

public class ImageManip {

	public ImageManip() {
		
	}
	
	public static BufferedImage makeColorTransparent(BufferedImage in, int r, int g, int b) {
		Color bgColor = new Color(r,g,b);

		int width = in.getWidth();
		int height = in.getHeight();

		BufferedImage dimg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

		Graphics2D g2d = dimg.createGraphics();
		g2d.setComposite(AlphaComposite.Src);
		g2d.drawImage(in, null, 0, 0);
		g2d.dispose();

		//Go Through Every Pixel
		for(int i = 0; i < dimg.getHeight(); i++) {
			for(int j = 0; j < dimg.getWidth(); j++) {
                //If Pixel matches one of the colors, turn transparent
                if(dimg.getRGB(j, i) == bgColor.getRGB()) {
                    dimg.setRGB(j, i, 0x8F1C1C);
                }
			}
		}

		//Return New Transparent Image
		return dimg;
	}
}
