Ok my problem is simple, after performing AffineTransform, my image is not saving properly (however it is drawn on JPanel properly!). It is really strange, so any hints are really appreciated...
好吧我的问题很简单,在执行AffineTransform后,我的图像没有正确保存(但是它正确地在JPanel上绘制!)。这真的很奇怪,所以任何提示都非常感激......
Take a look on code:
看看代码:
public BufferedImage performRotation(BufferedImage bi){
if (angle!=180){
at.translate(0.5*bi.getHeight(), 0.5*bi.getWidth());
if(clockwise){
at.rotate(Math.toRadians(angle));
}else{
at.rotate(Math.toRadians(-angle));
}
at.translate(-0.5*bi.getWidth(), -0.5*bi.getHeight());
}
else if(angle==180){
at.translate(0.5*bi.getWidth(), 0.5*bi.getHeight());
at.rotate(Math.toRadians(angle));
at.translate(-0.5*bi.getWidth(), -0.5*bi.getHeight());
}
AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
BufferedImage bi2 = op.filter(bi, null);
try {
ImageIO.write(bi, "bmp", new File("BEFORE filterORIG.bmp"));
ImageIO.write(bi2, "bmp", new File("AFTER filterNEW.bmp"));
} catch (IOException ex) {
Logger.getLogger(DrawingField.class.getName()).log(Level.SEVERE, null, ex);
}
File BEFORE filterORIG is saved properly -> there is an image, but its pre-rotated.
文件BEFORE FILORIG正确保存 - >有一个图像,但它已预先旋转。
File AFTER... is saved as blank file.
文件AFTER ...保存为空白文件。
What is really interesting, is previously mentioned fact that this transformation is poperly shown on JPanel that i use as a display (i can observe effect of desired transformation)
真正有趣的是,之前提到的事实是这个转换在JPanel上显示我用作显示器(我可以观察到所需转换的效果)
Any help appreciated...
任何帮助表示...
1 个解决方案
#1
0
Try writing png
images, ie:
尝试编写png图像,即:
ImageIO.write(bi, "png", new File("BEFORE filterORIG.png"));
ImageIO.write(bi2, "png", new File("AFTER filterNEW.png"));
The resulting image (bi2) may have an aplha channel and ImageIO
may not allow to encode images with aplha as bmp
.
得到的图像(bi2)可能具有aplha通道,并且ImageIO可能不允许将具有aplha的图像编码为bmp。
Alternatively, create a destination image with TYPE_INT_RGB
color model and use it as a second argument in filter()
method.
或者,使用TYPE_INT_RGB颜色模型创建目标图像,并将其用作filter()方法中的第二个参数。
#1
0
Try writing png
images, ie:
尝试编写png图像,即:
ImageIO.write(bi, "png", new File("BEFORE filterORIG.png"));
ImageIO.write(bi2, "png", new File("AFTER filterNEW.png"));
The resulting image (bi2) may have an aplha channel and ImageIO
may not allow to encode images with aplha as bmp
.
得到的图像(bi2)可能具有aplha通道,并且ImageIO可能不允许将具有aplha的图像编码为bmp。
Alternatively, create a destination image with TYPE_INT_RGB
color model and use it as a second argument in filter()
method.
或者,使用TYPE_INT_RGB颜色模型创建目标图像,并将其用作filter()方法中的第二个参数。