Java 旋转图像质量下降

标签 java image-processing rotation

我有旋转图像的功能。虽然我正在失去质量。有什么改变可以改善它吗?

 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/

相关文章:

java - Android 上的位图 LockBits?

python-3.x - 根据颜色分割图像

android - 在谷歌地图中旋转的颗粒状标记

java - 跳过 while 循环的第一行

java - 如何将列表从类(class)传递到 Activity ?

java - printf错误无法启动java eclipse

html - 拖动旋转 SVG :g group

java - fragment 调试 GPU overdraw

python - 在 Python 中估计图像的亚像素值

android - getDefaultDisplay().getRotation();总是返回相同的值