Java BufferedImage Operation findColor(BufferedImage image, int startX, int startY, int dirX, int dirY, int colorIndex)

Here you can find the source of findColor(BufferedImage image, int startX, int startY, int dirX, int dirY, int colorIndex)

Description

find Color

License

Apache License

Declaration

private static Point findColor(BufferedImage image, int startX, int startY, int dirX, int dirY,
            int colorIndex) 

Method Source Code

//package com.java2s;
/** 2048 playa - a 2048 autonomous player. 
 * Copyright 2014-2015 MeBigFatGuy.com //from  w  ww .  j  a  v a 2  s. c  o m
 * Copyright 2014-2015 Dave Brosius 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, 
 * software distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and limitations 
 * under the License. 
 */

import java.awt.Point;

import java.awt.image.BufferedImage;
import java.awt.image.Raster;

public class Main {
    private static Point findColor(BufferedImage image, int startX, int startY, int dirX, int dirY,
            int colorIndex) {

        int curX = startX;
        int curY = startY;
        int[] pixel = new int[1];

        Raster r = image.getRaster();
        do {
            r.getPixel(curX, curY, pixel);
            if (pixel[0] == colorIndex) {
                return new Point(curX, curY);
            }
            curX += dirX;
            curY += dirY;
        } while (true);
    }
}

Related

  1. ensureRGBAImage(BufferedImage img)
  2. fadeImageByShape(BufferedImage bimg, Shape arbshape, double alpha, int rule)
  3. fadeImages(BufferedImage source1, BufferedImage source2, BufferedImage target, int relX, int targetX)
  4. fakeAOI(final BufferedImage pImage, final Rectangle pSourceRegion)
  5. findavg(BufferedImage bimg)
  6. findDifference(BufferedImage img2, BufferedImage img1)
  7. findDominantColor(BufferedImage paramBufferedImage)
  8. findLegacyColorModel(BufferedImage image)
  9. findLegendLH(BufferedImage bufferedImage)