0

我在使用包来显示图像时遇到了一些问题,它适用于某些图像,但不适用于其他图像。我试过改变图像格式,但这没有任何区别,输出看起来像这样;http://tinypic.com/r/289bn92/5。这是代码的问题吗?或图像的格式?

这是我的代码:

import java.awt.Color;
import iptoolkit.*;

public class FindArea {

  public static void main(String[] args){
    int area = 0;

    String imageDir = "C:/Users/John/Dropbox/finalYear/Project/Leaves/";
    MainWindow mw = new MainWindow();

    IntImage src = new IntImage(imageDir + "ashLeafBW.jpg", 256, 256);

    src.displayImage(); //displays the image in a window

    for (int row = 0; row < src.getRows(); row++)
    {
        for (int col=0; col < src.getCols(); col++)
        {
            int pixel = src.pixels[row][col];
            int  red = (pixel & 0x00ff0000) >> 16;
            int  green = (pixel & 0x0000ff00) >> 8;
            int  blue = pixel & 0x000000ff;
            // and the Java Color is ...
            Color color = new Color(red,green,blue);

            if((color.getRed() == 0) & (color.getBlue() == 0) & (color.getGreen() == 0))
                area++;
        }
    }
    System.out.print("The area of the leaf is: " +area);
  }
}

该程序应该显示一片叶子的图像并计算该叶子的面积。任何帮助将不胜感激

4

0 回答 0