Java Utililty Methods BufferedImage Transparent

List of utility methods to do BufferedImage Transparent

Description

The list of methods to do BufferedImage Transparent are organized into topic(s).

Method

BufferedImageApplyTransparency(BufferedImage image, Image mask)
Apply a mask (alpha channel on a image)
BufferedImage dest = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = dest.createGraphics();
g2.drawImage(image, 0, 0, null);
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.DST_IN, 1.0F);
g2.setComposite(ac);
g2.drawImage(mask, 0, 0, null);
g2.dispose();
return dest;
...
BufferedImageapplyTransparency(BufferedImage src, float alpha)
apply Transparency
BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = dest.createGraphics();
g.drawImage(src, 0, 0, null);
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.DST_IN, 1.0f);
g.setComposite(ac);
float a = Math.max(0, Math.min(1, alpha));
g.setColor(new Color(0f, 0f, 0f, a));
g.fillRect(0, 0, dest.getWidth(), dest.getHeight());
...
booleanbordersNonTransparentPixel(BufferedImage data, int wid, int hei, boolean[] traced, int x, int y)
Returns whether the given pixel is bordered by any non-transparent pixel.
if (y > 0) {
    for (int rxx = x - 1; rxx <= x + 1; rxx++) {
        if (rxx < 0 || rxx >= wid || traced[((y - 1) * wid) + rxx]) {
            continue;
        if ((data.getRGB(rxx, y - 1) & TRANS_MASK) != 0) {
            return true;
if (x > 0 && !traced[(y * wid) + (x - 1)]) {
    if ((data.getRGB(x - 1, y) & TRANS_MASK) != 0) {
        return true;
if (x < wid - 1 && !traced[(y * wid) + (x + 1)]) {
    if ((data.getRGB(x + 1, y) & TRANS_MASK) != 0) {
        return true;
if (y < hei - 1) {
    for (int rxx = x - 1; rxx <= x + 1; rxx++) {
        if (rxx < 0 || rxx >= wid || traced[((y + 1) * wid) + rxx]) {
            continue;
        if ((data.getRGB(rxx, y + 1) & TRANS_MASK) != 0) {
            return true;
return false;
BufferedImageConvToTransparentImage(BufferedImage src, float alpha)
Conv To Transparent Image
BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = dest.createGraphics();
int rule = AlphaComposite.SRC_OVER;
AlphaComposite ac = AlphaComposite.getInstance(rule, alpha);
g2.setComposite(ac);
g2.drawImage(src, null, 0, 0);
g2.dispose();
return dest;
...
BufferedImagecutTransparentBorder(BufferedImage src)
Remove transparent border around an image.
int top = 0;
int left = 0;
int bottom = 0;
int right = 0;
topcheck: for (int y = 0; y < src.getHeight(); y++) {
    for (int x = 0; x < src.getWidth(); x++) {
        int c = src.getRGB(x, y);
        if ((c & 0xFF000000) != 0) {
...
BufferedImagefixTransparency(String var0, BufferedImage var1)
fix Transparency
if (var1 == null) {
    return var1;
} else {
    long var2 = System.currentTimeMillis();
    var1 = convertToARGB(var1);
    int var4 = var1.getWidth();
    int var5 = var1.getHeight();
    IntBuffer var6 = getARGBAsIntBuffer(var1);
...
voidmakeTransparency(BufferedImage image, int color)
make Transparency
int width = image.getWidth();
int height = image.getHeight();
int arrA[] = getArrayAlpha1D(image);
int arrC[] = getArrayColor1D(image);
for (int i = 0; i < width * height; i++) {
    if (arrC[i] == color) {
        arrA[i] = 0;
setArrayAlpha(image, arrA);
BufferedImagemakeTranspBufferedImage(Image image)
make Transp Buffered Image
if (waitForImage(image) == false)
    return null;
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
        BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = bufferedImage.createGraphics();
g2.drawImage(image, null, null);
int[] TRANSPARENT_COLOR = { 255, 255, 255, 0 };
WritableRaster raster = bufferedImage.getRaster();
...
intnonTransparentPixels(BufferedImage image)
Counts the numbers of non transparent pixels in a given BufferedImage .
int count = 0;
for (int x = 0; x < 8; x++) {
    for (int y = 0; y < 8; y++) {
        if (image.getRGB(x, y) == -1) {
            count++;
return count;
intpickBestTransparency(BufferedImage image)
pick Best Transparency
ColorModel colorModel = image.getColorModel();
if (colorModel.getTransparency() == Transparency.OPAQUE) {
    return Transparency.OPAQUE;
int width = image.getWidth();
int height = image.getHeight();
boolean foundTransparent = false;
for (int y = 0; y < height; y++) {
...