Hi dear all i am new in java i don't know how identify the background and foreground color of image if any have idea please help thanks in advance

You can read the image into an Image object, then use the PixelGrabber class to examine the individual pixels and get their colors, but after that it gets difficult - how exactly would you define "background color" and "foreground color" for some arbitrary image?

You said your new to Java. If thats the case then I would definately recommend not starting out with such an ambitious project.