Search code examples
javaandroidbitmapimagejcbir

ColorProcessor (ImageJ import library) will not take BitmapImage in Android


I am currently working with the Content Based Image Retrieval algorithm found on http://www.cise.ufl.edu/~fishwick/ac/2011/cbir_webpage/index.htm The algorithm is set to run on the JRE but I have replaced imports appropriately so that it will work on the ADT.Such as BufferedImage has been replaced with Bitmap. My problem is I keep getting a red line error on;

 ColorProcessor cp = new ColorProcessor(image);

The error reads; "The constructor ColorProcessor(Image) refers to the missing type Image". Can anyone point out to me what I am missing or not recognising. Any help will be much appreciated.

// a local version on the computer
            URL url = FeatureExtraction.class.getResource(name);
            System.out.println("url = " + url);
            Bitmap image = null;

            // ImageIO is not supported in Android SDK so use Bitmap to achieve the
                    // same thing.
                    //Bitmap img = BitmapFactory.decodeFile(name);
                    // System.out.println("image = " + img);


            try {
                //image = ImageIO.read(url);
                image = BitmapFactory.decodeFile(name);
                //image  = BitmapFactory.decodeStream(url.openConnection().getInputStream());
            } catch(IOException e) {
                System.out.println("read error: " + e.getMessage());
            }

            ColorProcessor cp = new ColorProcessor(image);

Solution

  • The error is actually complaining about another piece of code, the ColorProcessor constructor, which takes an argument of type java.awt.Image (http://rsb.info.nih.gov/ij/developer/api/ij/process/ColorProcessor.html).

    The complaint is that it can't find the java.awt.Image class definition, which I don't believe is available in Android (See How to add java.awt.image package in Android).

    Anyhow, you can't pass your image variable to new ColorProcessor() because it is of type android.graphics.bitmap (http://developer.android.com/reference/android/graphics/Bitmap.html) ... not at all related to java.awt.Image required by ColorProcessor.