Java BufferedImage Operation makeOpaque(BufferedImage img, Color col)

Here you can find the source of makeOpaque(BufferedImage img, Color col)

Description

make Opaque

License

Open Source License

Declaration

public static BufferedImage makeOpaque(BufferedImage img, Color col) 

Method Source Code


//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);
    }
}

Related

  1. makeCursor(BufferedImage img, int hotx, int hoty, String name)
  2. makeGhost(BufferedImage image)
  3. makeImageTranslucent(BufferedImage source, float alpha)
  4. makeItBlack(BufferedImage image)
  5. makeMouseover(final BufferedImage src)
  6. MakePoly(BufferedImage spr, int d, int angle, int baseX, int baseY)
  7. makeTintedCopy(BufferedImage bi, Color tint)
  8. markImageBorders(final BufferedImage img, final int startW, final int startH)
  9. matBytesToBufferedImage(byte[] data, int cols, int rows, int type)