我有旋转图像的功能。虽然我正在失去质量。有什么改变可以改善它吗?
public BufferedImage RotateImage(String imagePath,int degrees) throws IOException{
File file = new File(imagePath);
Image image = ImageIO.read(file);
BufferedImage img=bufferImage(image, BufferedImage.TYPE_INT_RGB);
AffineTransform tx = new AffineTransform();
double radians = (Math.PI / 180) * degrees;
double width = img.getWidth()/2;
double height = img.getHeight()/2;
if(degrees != 180){
tx.translate(height,width);
tx.rotate(radians);
tx.translate(-width,-height);
}else{
tx.rotate(radians,width, height);
}
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
img = op.filter(img, null);
return img;
}
最佳答案
Try using bicubic or bilinear 。链接显示了每个示例。
AffineTransformOp op =
new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
关于Java 旋转图像质量下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5436130/