Here you can find the source of makeOpaque(BufferedImage img, Color col)
public static BufferedImage makeOpaque(BufferedImage img, Color col)
//package com.java2s; /*//from w w w .j a va 2 s .c o m * Copyright (C) 2007, 2008 Quadduc <quadduc@gmail.com> * Copyright (C) 2007, 2011 IsmAvatar <IsmAvatar@gmail.com> * Copyright (C) 2007 Clam <clamisgood@gmail.com> * Copyright (C) 2013, 2014 Robert B. Colton * * This file is part of LateralGM. * LateralGM is free software and comes with ABSOLUTELY NO WARRANTY. * See LICENSE for details. */ import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedImage; public class Main { public static BufferedImage makeOpaque(BufferedImage img, Color col) { return convertImage(img, BufferedImage.TYPE_BYTE_INDEXED, col); } public static BufferedImage convertImage(BufferedImage img, int format, Color col) { BufferedImage bi = new BufferedImage(img.getWidth(), img.getHeight(), format); Graphics gd = bi.getGraphics(); if (col != null) { gd.setColor(col); gd.fillRect(0, 0, img.getWidth(), img.getHeight()); } gd.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), null); gd.dispose(); return bi; } public static BufferedImage convertImage(BufferedImage img, int format) { return convertImage(img, format, null); } }