Java BufferedImage Operation makeGhost(BufferedImage image)

Here you can find the source of makeGhost(BufferedImage image)

Description

Makes a ghost image suitable for dragging.

License

Open Source License

Parameter

Parameter Description
image The buffered image.

Declaration


public static void makeGhost(BufferedImage image) 

Method Source Code


//package com.java2s;
/*   Please see the license information at the end of this file. */

import java.awt.image.*;

public class Main {
    /**   Makes a ghost image suitable for dragging.
     *//from w  w w  .j a v  a  2  s .  c  om
     *   <p>All of the white pixels in the image are changed to transparent
     *   pixels. All other pixels have their intensity halved.
     *
     *   @param   image      The buffered image.
     */

    public static void makeGhost(BufferedImage image) {
        for (int i = 0; i < image.getWidth(); i++) {
            for (int j = 0; j < image.getHeight(); j++) {
                int pixel = image.getRGB(i, j);
                if (pixel == -1) {
                    image.setRGB(i, j, 0);
                } else {
                    int alpha = (pixel & 0xff000000);
                    int red = (pixel & 0x00ff0000) >> 16;
                    int green = (pixel & 0x0000ff00) >> 8;
                    int blue = pixel & 0x000000ff;
                    red = 255 - (255 - red) / 2;
                    green = 255 - (255 - green) / 2;
                    blue = 255 - (255 - blue) / 2;
                    pixel = alpha | (red << 16) | (green << 8) | blue;
                    image.setRGB(i, j, pixel);
                }
            }
        }
    }
}

Related

  1. interp(BufferedImage img1, BufferedImage img2, int weight1, int weight2)
  2. knit(BufferedImage[] buffImages)
  3. layer(BufferedImage source, BufferedImage destination, int x, int y)
  4. makeBinary(BufferedImage image, int threshold)
  5. makeCursor(BufferedImage img, int hotx, int hoty, String name)
  6. makeImageTranslucent(BufferedImage source, float alpha)
  7. makeItBlack(BufferedImage image)
  8. makeMouseover(final BufferedImage src)
  9. makeOpaque(BufferedImage img, Color col)