get Opaque Mask - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

get Opaque Mask

Demo Code

/*//www  .j  a v a 2 s.co  m
 *   Copyright (C) 2012 Markus Niedermann
 *   
 *   This program 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 3 of the License, or
 *   any later version.
 *   
 *   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//package com.java2s;

import java.awt.image.BufferedImage;

public class Main {
    private static boolean[][] getOpaqueMask(final BufferedImage src,
            final int opaqueLimit) {
        boolean[][] opaque = new boolean[src.getHeight()][src.getWidth()];
        for (int y = 0; y < src.getHeight(); y++) {
            for (int x = 0; x < src.getWidth(); x++) {
                if (((src.getRGB(x, y) >> 24) & 0xff) > opaqueLimit) {
                    opaque[y][x] = true;
                }

            }
        }
        return opaque;
    }
}

Related Tutorials