Here you can find the source of makeGhost(BufferedImage image)
Parameter | Description |
---|---|
image | The buffered image. |
public static void makeGhost(BufferedImage image)
//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); } } } } }