Rotating BufferedImage changes its colors

前端 未结 3 1262
谎友^
谎友^ 2020-12-06 23:39

I\'m trying to code a class to seam carve images in x and y direction. The x direction is working, and to reduce the y direction I thought about simply rotating the image 90

3条回答
  •  伪装坚强ぢ
    2020-12-07 00:12

    The problem is with the AffineTransformOp You need :

    AffineTransformOp.TYPE_NEAREST_NEIGHBOR
    

    instead of the BILINEAR you have now.

    Second paragraph from documentation hints towards this.

    This class uses an affine transform to perform a linear mapping from 2D coordinates in the source image or Raster to 2D coordinates in the destination image or Raster. The type of interpolation that is used is specified through a constructor, either by a RenderingHints object or by one of the integer interpolation types defined in this class. If a RenderingHints object is specified in the constructor, the interpolation hint and the rendering quality hint are used to set the interpolation type for this operation.

    The color rendering hint and the dithering hint can be used when color conversion is required. Note that the following constraints have to be met: The source and destination must be different. For Raster objects, the number of bands in the source must be equal to the number of bands in the destination.

    So this works

    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    

提交回复
热议问题