androidcolorsgetpixel

How to get pixel color in a certain area


I have to implement a function in an Android application that return to me the color in a certain area of a image.

What I need is different from what the

getpixel() - Returns the color at the specified location

because I need to determine the color in a given area (eg. in a 3x3 px radius).

To make the idea briefly explain the operating principle of the app:

In an activity a picture of a car is shown through a TileView; each part (bonnet, bumper, wheel, etc.) is colored differently (grayscale), while the edge of the car is black.

At each touch I go to sample the color at the x, y coordinate, compare it with a list of colors present in a db and finally return the name of the component.

Everything works perfectly except when I approach the edge of the image (black), this being a JPG the edge tends to be blurred and the colors sampled can be "wrong" (belonging to other components).

What is the best solution to do this ? Is it my idea correct ?


Solution

  • For this, you might have to create a logic of your own. If I am getting this right you might want to do something like this,

    Create a method pass the area in any way you want then you by use of the

    getPixel()
    

    You can get colors of that area, There is a high possibility that will find multiple shades of one color or multiple colors also.

    So based on this you can store the list of colors you are getting and you can compare the most no of colors you get from your DB and write your logic for that.

    I have used this idea to get the icon color from the screen and write a text in that color something like NovaLauncher of android if you have seen.