This method gets the RGB from image. - Java 2D Graphics

Java examples for 2D Graphics:Image

Description

This method gets the RGB from image.

Demo Code


//package com.java2s;

import java.awt.image.BufferedImage;

public class Main {
    /**// w w  w  .  java  2s  .  co  m
     * This method gets the RGB from image. The {@code col} and {@code row}
     * could be out of border, this function will return nearest
     * color in border
     * @param image
     * @param row
     * @param col
     * @return
     */
    public static int getRGBExtended(BufferedImage image, int row, int col) {
        int width = image.getWidth();
        int height = image.getHeight();
        row = Math.max(0, Math.min(height - 1, row));
        col = Math.max(0, Math.min(width - 1, col));
        return image.getRGB(col, row);
    }
}

Related Tutorials