Java BufferedImage Operation showColors(BufferedImage image, boolean alpha, boolean red, boolean green, boolean blue)

Here you can find the source of showColors(BufferedImage image, boolean alpha, boolean red, boolean green, boolean blue)

Description

show Colors

License

Open Source License

Declaration

public static void showColors(BufferedImage image, boolean alpha, boolean red, boolean green, boolean blue) 

Method Source Code


//package com.java2s;
/*/*from  www.j a v a2 s. c om*/
 * DDSUtil.java - This file is part of Java DDS ImageIO Plugin
 *
 * Copyright (C) 2011 Niklas Kyster Rasmussen
 * 
 * COPYRIGHT NOTICE:
 * Java DDS ImageIO Plugin is based on code from the DDS GIMP plugin.
 * Copyright (C) 2004-2010 Shawn Kirst <skirst@insightbb.com>,
 * Copyright (C) 2003 Arne Reuter <homepage@arnereuter.de>
 *
 * Java DDS ImageIO Plugin is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Java DDS ImageIO Plugin is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Java DDS ImageIO Plugin; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * FILE DESCRIPTION:
 * TODO Write File Description for DDSUtil.java
 */

import java.awt.image.BufferedImage;

public class Main {
    public static void showColors(BufferedImage image, boolean alpha, boolean red, boolean green, boolean blue) {
        int a, r, g, b, rgb;
        for (int y = 0; y < image.getHeight(); ++y) {
            for (int x = 0; x < image.getWidth(); ++x) {
                rgb = image.getRGB(x, y);

                if (alpha) {
                    a = ((rgb >> 24) & 0xff);
                } else {
                    a = 255;
                }
                if (red) {
                    r = ((rgb >> 16) & 0xff);
                } else {
                    r = 0;
                }
                if (green) {
                    g = ((rgb >> 8) & 0xff);
                } else {
                    g = 0;
                }
                if (blue) {
                    b = (rgb & 0xff);
                } else {
                    b = 0;
                }

                rgb = (a << 24) | (r << 16) | (g << 8) | (b << 0);
                image.setRGB(x, y, rgb);
            }
        }
    }
}

Related

  1. setImageIntPixels(BufferedImage image, boolean allowDeoptimizingDirectRead, IntBuffer pixels)
  2. setLockImage(BufferedImage image)
  3. setLuminance(BufferedImage image, int x, int y, float value)
  4. setPixel(BufferedImage img, int x, int y, int c)
  5. setPoint(BufferedImage image, int x, int y, int factor, Color color)
  6. shrink(BufferedImage source, double factor)
  7. smaller(final BufferedImage src, final int radius, final int opaqueLimit)
  8. stitchImages(BufferedImage[] images, int[] relX)
  9. switchAxes(BufferedImage img)