2011-09-13 7 views
3

그레이 스케일에있는 이미지가 있으면 그 위치에서 그레이 스케일의 픽셀 값을 어떻게 얻을 수 있습니까?BufferedImage - Gray Scale

이 경우 온도는 항상 -16777216 (검정색)으로 출력됩니다.

imgMazeImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); 

픽셀이 기본값으로 생성하고 논리적 모두 동일한 색상을 가지고 (검은 색) : 새 빈 이미지를 생성하고 클래스 변수에 할당하는

public void testMethod() 
{ 
    int width = imgMazeImage.getWidth(); 
    int height = imgMazeImage.getHeight(); 

    //Assign class variable as a new image with RGB formatting 
    imgMazeImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); 
    for(int i=0; i < width; i ++){ 
     for(int j=0; j < height; j++) 
     { 
      //Grab and set the colors one-by-one 
      inttemp = imgMazeImage.getRGB(j, i); 
      System.out.println(temp); 
     } 
    } 
} 

답변

2

어떤 픽셀의 색상도 아직 조작하지 않았으므로 인쇄 할 단계에서.

너비가 높이와 같지 않으면 코드가 실패 할 수 있습니다. 당신의 for 루프에 따르면, 나는 너비에 따라 달리며 j는 높이에 따라 달립니다. 따라서

int temp = imgMazeImage.getRGB(i, j); 

int temp = imgMazeImage.getRGB(j, i); 

을 변경해야합니다