Java BufferedImage Operation checkRadius(final BufferedImage src, final int x, final int y, final int opaqueLimit, final int radius)

Here you can find the source of checkRadius(final BufferedImage src, final int x, final int y, final int opaqueLimit, final int radius)

Description

check Radius

License

Open Source License

Declaration

private static boolean checkRadius(final BufferedImage src, final int x, final int y, final int opaqueLimit,
            final int radius) 

Method Source Code

//package com.java2s;
/*/*w w w  .  j  av a2 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/>.
 */

import java.awt.image.BufferedImage;

public class Main {
    private static boolean checkRadius(final BufferedImage src, final int x, final int y, final int opaqueLimit,
            final int radius) {
        int minX = Math.max(x - radius, 0);
        int maxX = Math.min(src.getWidth(), x + radius);

        int minY = Math.max(y - radius, 0);
        int maxY = Math.min(src.getHeight(), y + radius);

        for (int curY = minY; curY < maxY; curY++) {
            for (int curX = minX; curX < maxX; curX++) {
                if (getDistance(curX, curY, x, y, radius) <= 1
                        && ((src.getRGB(curX, curY) >> 24) & 0xff) <= opaqueLimit) {
                    return false;
                }
            }
        }
        return true;
    }

    private static double getDistance(final int curX, final int curY, final int x, final int y, final int radius) {
        return Math.sqrt((curX - x) * (curX - x) + (curY - y) * (curY - y)) / radius;
    }
}

Related

  1. changeContrast(BufferedImage img, float amount)
  2. changeImageToArray(BufferedImage bufferedImage)
  3. checkIfManyColors(BufferedImage image)
  4. checkImageMatch(BufferedImage img1, String imgName1, BufferedImage img2, String imgName2)
  5. checkImageType(BufferedImage img, String name)
  6. chunk(BufferedImage image)
  7. circularize(BufferedImage image)
  8. cleanBinaryImage(BufferedImage image)
  9. compose(BufferedImage image, BufferedImage mask)