Java Utililty Methods BufferedImage Operation

List of utility methods to do BufferedImage Operation

Description

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

Method

BufferedImageappendImages(BufferedImage leftImage, BufferedImage rightImage)
Appends rightImage to the right side of leftImage.
Preconditions.checkNotNull(leftImage);
Preconditions.checkNotNull(rightImage);
int width = leftImage.getWidth() + rightImage.getWidth();
int height = Math.max(leftImage.getHeight(), rightImage.getHeight());
BufferedImage result = new BufferedImage(width, height, leftImage.getType());
result.createGraphics().drawImage(leftImage, 0, 0, null);
result.createGraphics().drawImage(rightImage, leftImage.getWidth(), 0, null);
return result;
...
voidapplyAlphaMask(BufferedImage buffer, BufferedImage alphaMask, int imgHeight)
apply Alpha Mask
Graphics2D g2 = buffer.createGraphics();
g2.setComposite(AlphaComposite.DstOut);
g2.drawImage(alphaMask, null, 0, imgHeight);
g2.dispose();
BufferedImageapplyExplicitSMask(BufferedImage baseImage, BufferedImage sMaskImage)
apply Explicit S Mask
BufferedImage[] images = scaleImagesToSameSize(baseImage, sMaskImage);
baseImage = images[0];
sMaskImage = images[1];
int baseWidth = baseImage.getWidth();
int baseHeight = baseImage.getHeight();
BufferedImage argbImage;
if (hasAlpha(baseImage)) {
    argbImage = baseImage;
...
BufferedImageapplyGrayDecode(BufferedImage rgbImage, int bitsPerComponent, float[] decode)
apply Gray Decode
WritableRaster wr = rgbImage.getRaster();
int[] cmap = null;
if (bitsPerComponent == 1) {
    boolean defaultDecode = 0.0f == decode[0];
    cmap = defaultDecode ? GRAY_1_BIT_INDEX_TO_RGB : GRAY_1_BIT_INDEX_TO_RGB_REVERSED;
} else if (bitsPerComponent == 2) {
    cmap = GRAY_2_BIT_INDEX_TO_RGB;
} else if (bitsPerComponent == 4) {
...
BufferedImageapplyGrayscaleMaskToAlpha(BufferedImage image, BufferedImage mask)
apply Grayscale Mask To Alpha
BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
int width = image.getWidth();
int height = image.getHeight();
int[] imagePixels = image.getRGB(0, 0, width, height, null, 0, width);
int[] maskPixels = mask.getRGB(0, 0, width, height, null, 0, width);
for (int i = 0; i < imagePixels.length; i++) {
    int color = imagePixels[i] & 0x00ffffff; 
    int alpha = maskPixels[i] << 24; 
...
BufferedImageapplyMask(BufferedImage img, Color keyColor)
Applying mask into image using specified masking color.
BufferedImage alpha = new BufferedImage(img.getWidth(), img.getHeight(), Transparency.BITMASK);
Graphics2D g = alpha.createGraphics();
g.setComposite(AlphaComposite.Src);
g.drawImage(img, 0, 0, null);
g.dispose();
for (int y = 0; y < alpha.getHeight(); y++) {
    for (int x = 0; x < alpha.getWidth(); x++) {
        int col = alpha.getRGB(x, y);
...
voidapplyMaskImage(BufferedImage src, int x, int y, int w, int h)
apply Mask Image
if (x < 0) {
    x = 0;
if (y < 0) {
    y = 0;
int maxOffsetX = x + w;
int maxOffsetY = y + h;
...
voidapplyShadow(BufferedImage image)
apply Shadow
int dstWidth = image.getWidth();
int dstHeight = image.getHeight();
int left = (shadowSize - 1) >> 1;
int right = shadowSize - left;
int xStart = left;
int xStop = dstWidth - right;
int yStart = left;
int yStop = dstHeight - right;
...
booleanareBufferedImagesEqual(BufferedImage img1, BufferedImage img2)
are Buffered Images Equal
if (img1 == null && img2 == null) {
    return true;
} else if (img1 == null || img2 == null) {
    return false;
} else if (img1.getWidth() == img2.getWidth() && img1.getHeight() == img2.getHeight()) {
    for (int x = 0; x < img1.getWidth(); x++) {
        for (int y = 0; y < img1.getHeight(); y++) {
            if (img1.getRGB(x, y) != img2.getRGB(x, y)) {
...
BufferedImageautoPanImage(BufferedImage img, Color bgcolor)
auto Pan Image
BufferedImage out = null;
if (img == null) {
    return null;
int bgcolorInt = bgcolor.getRGB();
int w = img.getWidth();
int h = img.getHeight();
int up = 0;
...