【发布时间】:2023-03-09 20:40:01
【问题描述】:
我正在尝试使用 ImageJ 调整图像大小和裁剪图像。代码如下:
ImagePlus ip1 = IJ.openImage("_Pic.jpg");
ImagePlus ip2 = IJ.openImage("_Pic.jpg");
ImageProcessor imgP1 = ip1.getProcessor();
ImageProcessor imgP2 = ip2.getProcessor();
FileSaver fs1 = new FileSaver(ip1);
FileSaver fs2 = new FileSaver(ip2);
/* Trying to resize */
imgP1.resize(100); // also tried with width and height
fs1.saveAsJpeg("Resized.jpg");
/* Trying to crop */
imgP2.setRoi(100, 100, 200, 200);
imgP2.crop();
fs2.saveAsJpeg("Cropped.jpg");
很遗憾,新创建的文件与原始文件相同。
到目前为止,我已经发现了如何模糊、平滑、反转、平移、旋转……,但这两个让我很难受。有人有想法吗?
【问题讨论】:
-
你的例子有很多问题。类
ImagePlus不存在resize()方法。imgP12和imgP13未定义。等等......我建议在开发 Java 代码时使用像 Eclipse 这样的 IDE。另外,请查看Javadoc。最后,对于 ImageJ 特定的问题,最好在ImageJ forum 上提问。 -
@JanEglinger 感谢您的评论。我以某种方式打错了...我在
imgP12和imgP13上使用resize()方法,这应该是ImageProcessor实例(而不是imgP1和imgP2)。我正在使用 Eclipse 并且没有语法错误,我只是在复制和粘贴时犯了一个错误..