2017-12-23 3 views
0

Java에서 이미지 회전을위한 메소드를 작성했습니다 (회전 수는 90, 180 및 270도).하지만 제대로 작동하지 않는 것으로 보입니다. 나는 틀린 일을 분명히하고 있지만, 무엇을 알아 내지 못하고있다. 출력에 관한 문제는 이미지가 실제로 회전되어 있지만 이미지가 올바른 위치에 있지 않은 것처럼 검은 이미지가있는 것입니다.자바에서 버퍼링 된 이미지 회전

return affineTransformOp.filter(bufferedImage, null); 

그리고 회전 이미지의 아니 검은 부분 좋았지 만, 색상이 같은 이상한 :

내 첫 번째 시도 대신 내가 이런 짓을, 내가 대상으로 사용 결과 변수없이 그것을 할 수 있었다 일부 색상이 변경되면 피부색이 빨간색으로 변합니다. 그래서 다른 누군가가 똑같은 문제를 겪고있는 것을 보았을 때 그것을 바 꾸었습니다.

이것은 내가 지금 무엇을 가지고 :

private BufferedImage rotateImage(ImageData imageData, BufferedImage bufferedImage) { 
    AffineTransform affineTransform = new AffineTransform(); 

    affineTransform.rotate(imageData.getRotation().getRotationAngle(), bufferedImage.getWidth()/2, bufferedImage.getHeight()/2); 

    AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_BILINEAR); 

    BufferedImage result = new BufferedImage(bufferedImage.getHeight(), bufferedImage.getWidth(), bufferedImage.getType()); 

    affineTransformOp.filter(bufferedImage, result); 

    return result; 
} 

는 또한 이미지를 변환 시도,하지만 많은 도움이되지 않았다.

정말 도움이됩니다. 고맙습니다.

답변

0

미래에 다른 사람이 같은 문제가있는 경우 대답을 찾았습니다.

private BufferedImage rotateImage(ImageRotation imageRotation, BufferedImage bufferedImage) { 
    AffineTransform affineTransform = new AffineTransform(); 

    if (ImageRotation.ROTATION_90.equals(imageRotation) || ImageRotation.ROTATION_270.equals(imageRotation)) { 
     affineTransform.translate(bufferedImage.getHeight()/2, bufferedImage.getWidth()/2); 
     affineTransform.rotate(imageRotation.getRotationAngle()); 
     affineTransform.translate(-bufferedImage.getWidth()/2, -bufferedImage.getHeight()/2); 

    } else if (ImageRotation.ROTATION_180.equals(imageRotation)) { 
     affineTransform.translate(bufferedImage.getWidth()/2, bufferedImage.getHeight()/2); 
     affineTransform.rotate(imageRotation.getRotationAngle()); 
     affineTransform.translate(-bufferedImage.getWidth()/2, -bufferedImage.getHeight()/2); 

    } else { 
     affineTransform.rotate(imageRotation.getRotationAngle()); 
    } 

    AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_BILINEAR); 

    BufferedImage result; 

    if (ImageRotation.ROTATION_90.equals(imageRotation) || ImageRotation.ROTATION_270.equals(imageRotation)) { 
     result = new BufferedImage(bufferedImage.getHeight(), bufferedImage.getWidth(), bufferedImage.getType()); 

    } else { 
     result = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), bufferedImage.getType()); 
    } 

    affineTransformOp.filter(bufferedImage, result); 

    return result; 
} 
:

내 문제를 해결 Java 메소드를 수정
관련 문제