how to fill color in image in particular area?

I want to fill the color in white area for Paint based application
so please give me suggestion for how to do this work..

enter image description here

  • how to resolve UnsupportedOperationException Required method destroyItem was not overridden
  • How to start an Android activity from a Unity Application?
  • GL Wallpaper example only shows green screen in Emulator, but it's working in device
  • Android SAX parser not getting full text from between tags
  • Android: Flip Animation using XML for animation in android
  • Transparent background in ImageButton with ripple effect?
  • Android: How can I pass parameters to AsyncTask's onPreExecute()?
  • How do I run Lua scripts on Android in a Java application?
  • com.android.dx.util.DexException: Multiple dex files define
  • How to install an APK file on an Android phone?
  • How to disable cursor positioning and text selection in an EditText? (Android)
  • Defining IDs within style, is it safe or a disaster?
  • 3 Solutions collect form web for “how to fill color in image in particular area?”

    I found the Solution with Flood fill algoritham

    private void FloodFill(Bitmap bmp, Point pt, int targetColor, int replacementColor){
    Queue<Point> q = new LinkedList<Point>();
    q.add(pt);
    while (q.size() > 0) {
        Point n = q.poll();
        if (bmp.getPixel(n.x, n.y) != targetColor)
            continue;
    
        Point w = n, e = new Point(n.x + 1, n.y);
        while ((w.x > 0) && (bmp.getPixel(w.x, w.y) == targetColor)) {
            bmp.setPixel(w.x, w.y, replacementColor);
            if ((w.y > 0) && (bmp.getPixel(w.x, w.y - 1) == targetColor))
                q.add(new Point(w.x, w.y - 1));
            if ((w.y < bmp.getHeight() - 1)
                    && (bmp.getPixel(w.x, w.y + 1) == targetColor))
                q.add(new Point(w.x, w.y + 1));
            w.x--;
        }
        while ((e.x < bmp.getWidth() - 1)
                && (bmp.getPixel(e.x, e.y) == targetColor)) {
            bmp.setPixel(e.x, e.y, replacementColor);
    
            if ((e.y > 0) && (bmp.getPixel(e.x, e.y - 1) == targetColor))
                q.add(new Point(e.x, e.y - 1));
            if ((e.y < bmp.getHeight() - 1)
                    && (bmp.getPixel(e.x, e.y + 1) == targetColor))
                q.add(new Point(e.x, e.y + 1));
            e.x++;
        }
    }}
    

    flood fill in android:

    See this FloodFill

    Here’s a quick application using Python and OpenCV (should be available on Android if you try hard enough):

    """Flood fills with random color on click.  Press `q' to exit."""
    import cv
    import sys
    import random
    
    TOL = 10
    TOL_BGR = (TOL, TOL, TOL, 0)
    
    def click(event,x,y,flags,im):
        if event == cv.CV_EVENT_LBUTTONDOWN:
            b,g,r = [ random.random() * 255 for i in range(3) ]
            cv.FloodFill(im, (x,y), (b,g,r,0), TOL_BGR, TOL_BGR)
    
    im = cv.LoadImage(sys.argv[1], cv.CV_LOAD_IMAGE_COLOR)
    cv.NamedWindow(__file__, 1)
    cv.SetMouseCallback(__file__, click, im)
    while True:
        cv.ShowImage(__file__, im)
        key = cv.WaitKey(33)
        if chr(key & 0xff) == 'q':
            break
    cv.SaveImage('floodfill.png', im)
    

    Every time the user clicks an image, the application flood-fills using the click location as a seed. The color is picked randomly. You can change the tolerances by modifying the value of TOL (or TOL_BGR). Here’s the result after a couple of clicks:

    enter image description here

    The general algorithm is the same regardless of what technology you use.

    1)Have the Split up image for each color portion separately with same size as actual image and other portion are transparent.
    2)Have the complete image with each portion painting in different color in ur drawable folder – this is just reference image.

    3) Add the all split up images in frame layout and set all split up invisible initially and set visible to actual image only

    4) Hot code the color for each split up from ur reference image (step2) for Eg handSplitImageColor = green;

    4) Set the listener for frame layout find out the x and y position and pass the x and y position to ur reference image (step 2) and find out the color in that particular location and match the color with step 4 and fill the particular in that image and set the visibility true for that split up image. So only that portion will get filled by color since other portion are transparent.

    These are the steps i used for one of my same type of problems.

    But I don’t think this is the better solution but it works well for me.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.