- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 IM4J (ImageMagick 的 Java 包装器)来创建 JPEG 的缩略图,这是我(有史以来)对这两个库的第一次体验。请注意,这是我的技术主管向我提出的一项硬性要求(所以请不要建议使用除 IM4J/ImageMagick 以外的任何东西)解决方案 - 我的双手被束缚在此处的技术选择上!
我收到了 FileNotFoundException
在和 convert
命令告诉我我没有正确设置这些库之一(或两者)。
在我的电脑上,这是我的目录结构:
C:/
myApp/
images/ --> where all of my JPEGs are
thumbnails/ --> where I want ImageMagick to send the converted thumbnails to
imageMagickHome/ --> Where I downloaded the DLL to
ImageMagick-6.7.6-1-Q16-windows-dll.exe
...
在我的 Java 项目中,我确保 IM4J JAR (
im4java-1.2.0.jar
) 在运行时位于类路径中。虽然我需要使用 IM4J 的 1.2.0 版本,但我可以自由使用任何我想要的 ImageMagick 版本。我只是选择了这个版本,因为它似乎是我的 Windows 7(32 位)机器的最新/稳定版本。
如果我应该使用其他版本,请在您的答案中从 ImageMagick 下载页面向我发送指向它的链接!
// In my driver...
File currentFile = new File("C:/myApp/images/test.jpg"); --> exists and is sitting at this location
File thumbFile = new File("C:/myApp/thumbnails/test-thumb.jpg"); --> doesnt exist yet! (destination file)
Thumbnailer myThumbnailer = new Thumbnailer();
myThumbnailer.generateThumbnail(currentFile, thumbFile);
// Then the Thumbnailer:
public class Thumbnailer
{
// ... omitted for brevity
public void generateThumbnail(File originalFile, File thumbnailFile)
{
// Reads appConfig.xml from classpath, validates it against a schema,
// and reads the contents of an element called <imPath> into this
// method's return value. See below
String imPath = getIMPathFromAppConfigFile();
org.im4java.core.IMOperation op = new Operation();
op.colorspace(this.colorSpace);
op.addImage(originalFile.getAbsolutePath());
op.flatten();
op.addImage(thumbnailFile.getAbsolutePath());
ConvertCmd cmd = new ConvertCmd();
cmd.setSearchPath(imPath);
// This next line is what throws the FileNotFoundException
cmd.run(op);
}
}
我的 appConfig.xml 文件中包含 imPath 的部分:
<imPath>C:/myApp/imageMagickHome</imPath>
请注意 - 如果此 appConfig.xml 格式不正确,我们的模式 validator 将捕获它。由于我们没有收到架构验证错误,因此我们可以将其排除为罪魁祸首。
然而 ,注意我的文件路径分隔符;它们都是正斜杠。我这样做是因为有人告诉我,在 Windows 系统上,正斜杠被视为与 *nix 反斜杠相同,引用文件路径。信不信由你,我们正在 Windows 上开发
IM4JAVA_TOOLPATH
的文章env var 让这个库工作。我尝试了这个建议,创建了一个新的同名系统范围环境变量并将其值设置为
C:\myApp\imageMagickHome
.还是没有区别。
但请注意这里我使用了反斜杠 .这是因为这个 env var 在我的机器上是本地的,而 appConfig.xml 是一个配置描述符,它被部署到 linux 服务器上。
FileNotFoundException
在名为“convert”的文件上:
java.io.FileNotFoundException: convert
cmd.run(op)
之前开始。调用并创建
convert
文件,也许这就是我所缺少的(也许我需要在执行我的
CmdScriptGenerator
方法之前手动启动其中一个生成器,例如
Thumbnailer
。或者,也许我的下载不完整。
最佳答案
首先运行“ImageMagick-6.7.6-1-Q16-windows-dll.exe”安装程序以安装 imagemagick 库。然后确保您的环境路径包含已安装二进制文件的位置(“convert.exe”、“mogrify.exe”等)
关于java - ImageMagick/IM4J FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10213249/
我在 VisualStudio2010 中创建了小的 Windows Forms progs,只是为了业余爱好。释放它们后,我使用 .exe 文件在其他 PC 上运行它们,而无需 进行任何安装。这些
我正在尝试使用AvroParquetWriter将Avro格式的文件转换为 Parquet 文件。我加载架构 val schema:org.apache.Schema = ... getSchema(
我正在尝试使用 Image.IO.Write() 保存图像;我基本上从 here 复制了标准代码使用 lwjgl 截取屏幕截图。我唯一做的就是使用现有目录作为保存路径来初始化文件。 当我尝试保存图像时
错误: E/BitmapFactory﹕ Unable to decode stream: java.io.FileNotFoundException: /file:/storage/sdcard0/
如果这是基本的,我很抱歉,我错过了一些简单的东西。我正在尝试运行下面的代码以遍历文件夹中的文件并将所有以特定字符串开头的文件合并到数据框中。所有文件都放在一个湖中。 file_list=[] path
在我的数据库中,我的手机上的每个条目都有一个图片的 uri。为了在手机上显示它,Listview 有一个 CustomAdapter。现在,我想在 ListView 中显示图片,得到如下错误信息: 0
我的所有节点在压缩期间都抛出 FileNotFoundException。因此,没有一个压缩(自动、手动)可以完成,我的 SSTable 计数现在是单个 CF (CQL3) 的数千个。 nodetoo
我在 java 中读取文件时遇到一些问题: 我的文件是例如: 3,4 2 6 4 1 7 3 8 9 其中第一行 3 和 4 是数组 A 和 B 的长度,然后是每个数组的元素。 我做的 import
我创建了一个程序,其中保存了学生的成绩,我想将这些成绩存储在txt文件中,然后在启动程序时,导入成绩,并在程序完成后导出成绩。我将import和exportTo方法放在单独的文件中,然后在主类中调用这
我怎样才能捕获一个 com.sun.faces.context.FacesFileNotFoundException 在 Java EE 网络应用程序中? 我尝试在我的 web.xml 文件中添加以下
请帮忙,我正在尝试从此谷歌翻译 API URL 获取数据仅当值为 1 个单词时它才有效。如果值为 2,则会出现错误。 我的意思是这个值会起作用: String sourceLang = "auto";
当我尝试使用retrofit2上传图片时,出现此错误 :java.io.FileNotFoundException(No such file or directory). HashMap partMa
try { FileReader fr = new FileReader("C:\\Users\\kevin\\Desktop\\AndroidLibr\\LeagueStats\\a
我尝试使用 Java 将单个文件从源复制到目标,但收到以下错误消息。 java.io.FileNotFoundException:以下是方法 public void copy_single(Strin
类似的问题涉及 C: 上的文件。驱动器,其中对文件路径进行硬编码是可接受的答案。此应用程序是移动应用程序,对文件路径进行硬编码并不实用。 我正在尝试通过扫描仪导入一个文本文件,其中包含一个字符串列表,
我正在修改一个小应用程序以从文件中读取一些数字。到目前为止一切都运行良好,但现在我遇到了一个问题,我不知道如何有效地解决它。如果用户输入了错误的文件名(可能是无意的),JVM 将抛出 FileNotF
我有一个 Web 项目,其中使用以下代码: try { br1 = new BufferedReader(new FileReader("queryWords.txt")); } catch
我尝试使用绝对路径从文件系统读取文件,但由于“FileNotFoundException”而失败,我不知道为什么 File file=new File("E:\\Directory\\File.txt
在我当前的项目中,我遇到了未收到文件未找到异常的问题。我的驱动程序文件将要打开的路径传递给正在构建图书库的构造函数。我正在使用 JFileChooser 来获取路径。在尝试强制错误(输入不存在的文件名
这个问题已经有答案了: Java: Unresolved compilation problem (10 个回答) 已关闭 4 年前。 我已经查看了有关此问题的其他答案,并尝试了他们的建议,但没有成功
我是一名优秀的程序员,十分优秀!