2015-01-26 3 views
1

g2 구성 요소에 회전 된 그림을 그리는 기능이 있지만 어떤 이유로 든 색이있는 배경을 제공 할 수 없습니다. 메서드를 사용하려고했습니다 .setColor) 및 .setBackground()를 사용하지만 사용하지 마십시오. 나는이 비슷한 경우를 보았습니다 Graphics2D: Drawing black on white? 하지만 실제로 도움이되지 않았습니다.그래픽 2D가 흑백 배경으로 회전합니다.

 public void rotateImage1(double degrees, ImageObserver o){ 

     double sin = Math.abs(Math.sin(Math.toRadians(degrees))); 
     double cos = Math.abs(Math.cos(Math.toRadians(degrees))); 
     ImageIcon icon = new ImageIcon(this.spiral); 
     int w = icon.getIconWidth(); 
     int h = icon.getIconHeight(); 
     int neww = (int)Math.floor(w*cos+h*sin); 
     int newh = (int)Math.floor(h*cos+w*sin); 
     BufferedImage blankCanvas = new BufferedImage(neww, newh, BufferedImage.TYPE_INT_ARGB); 
     Graphics2D g2 = (Graphics2D)blankCanvas.getGraphics(); 
     if(PhotoEdit.black) 
      g2.setColor(Color.BLACK); 
     else 
      g2.setColor(Color.WHITE); 
     g2.translate((neww-w)/2, (newh-h)/2); 
     g2.rotate(Math.toRadians(degrees), icon.getIconWidth()/2, icon.getIconHeight()/2); 

     g2.drawImage(this.spiral, 0, 0, o); 
     this.spiral = blankCanvas; 
} 

PhotoEdit.black 사용자가 검은 배경 옵션을 체크 박스를 선택한 경우 true 인 부울 변수 : 여기 내 기능입니다.

+0

당신은 "나는 어떤 색깔의 배경을 줄 수 없습니다."무엇을 의미합니까 이렇게하려고 할 때 구체적으로 무엇이 일어나고 있습니까? – NoseKnowsAll

+0

내 말은, 회전으로 인해 45도 정도의 공백이 생겨서 그림을 회전시킬 때입니다. 나는 그들을 색칠하고 싶다. 일반적으로 흰색입니다. –

+0

회전 된 객체를 그리는 방법에 문제가없는 것처럼 들리지만 배경을 그리는 방법에 문제가있는 것 같습니다. 객체를 회전 할 때마다 올바른 색상을 설정하고 배경을 다시 그려야합니까? – NoseKnowsAll

답변