使用包显示图像

时间:2013-11-02 14:46:25

标签: java image-processing

我在使用包显示图像时遇到一些问题,它对某些图像非常有效,但对其他图像则不然。我试过改变图像格式,但这没有任何区别,输出看起来像这样; 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);
  }
}

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

0 个答案:

没有答案