Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.Rect;

public class Main {

    public static int hasColorOnRect(Bitmap src, Rect serchRect, int inputColor) {
        int width = serchRect.width();
        int height = serchRect.height();

        if (width == 0 || height == 0)
            return inputColor;

        int color = inputColor;
        if (width == 1 && height == 1) {
            color = src.getPixel(serchRect.left, serchRect.top);
            return color != inputColor ? color : inputColor;
        }
        if (width == 1 && height > 1) {
            for (int start = 0; start < height; ++start) {
                color = src.getPixel(serchRect.left, serchRect.top + start);
                if (color != inputColor)
                    return color;
            }
            return inputColor;
        }
        if (width > 1 && height == 1) {
            for (int start = 0; start < width; ++start) {
                color = src.getPixel(serchRect.left + start, serchRect.top);
                if (color != inputColor)
                    return color;
            }
            return inputColor;
        }
        if (width > 1 && height > 1) {
            for (int x = 0; x < width; ++x) {
                for (int y = 0; y < height; ++y) {
                    color = src.getPixel(serchRect.left + x, serchRect.top + y);
                    if (color != inputColor)
                        return color;
                }
            }

            return inputColor;
        }

        return inputColor;
    }
}