旋转图像会导致损坏
我正在尝试将图像左右旋转 90 度。
但由于某种原因,此过程的输出会导致腐败。
这是我的代码:
(它很酷,但不需要太多想象力就可以假装它的java)
void rotate(File file){
def image = ImageIO.read(file);
double theta = Math.PI / 2;
def w = image.width / 2;
def h = image.height / 2;
def transform = new AffineTransform();
transform.rotate(theta, h, w);
def op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
image = op.filter(image, null);
def name = file.getName();
def type = name.substring(name.lastIndexOf(".") + 1, name.length());
ImageIO.write(image,type,file);
}
原始:
旋转:
I am trying to rotate and image left and right by 90 degrees.
For some reason though, the output of this process results in corruption.
Here is my code:
(its groovy but it doesnt take much imagination to pretend its java)
void rotate(File file){
def image = ImageIO.read(file);
double theta = Math.PI / 2;
def w = image.width / 2;
def h = image.height / 2;
def transform = new AffineTransform();
transform.rotate(theta, h, w);
def op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
image = op.filter(image, null);
def name = file.getName();
def type = name.substring(name.lastIndexOf(".") + 1, name.length());
ImageIO.write(image,type,file);
}
original:
rotated:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您所说的损坏指的是颜色变化,请取出过滤器。如果我正确理解语法的话,这会给你一个负面的印象。
每当我使用变换时,我都会关闭过滤器并手动完成它们。这确实需要花费很多时间,但它们总是变得更有用。只是一个建议。
If by corruption you are referring to the color change, take out the filter. That's giving you a negative image if I'm understanding the syntax properly.
Whenever I use transforms I leave filters off and do them by hand. It does take a lot of time, but they always turn out being more useful. Just a suggestion.
filter()
方法需要src
和dst
BufferedImage
,必须不同。The
filter()
method requires asrc
anddst
BufferedImage
, which must be different.