如何使用Apache Ant缩放图像? - 使用百分比问题

时间:2012-05-25 09:24:49

标签: java ant

我写了一个简单的任务来扩展我的图像,但它似乎有PNG文件的问题。

这是任务的内容[重要部分]:

 <image srcdir="${imgResizeDir}" destdir="${imgResizeDir}/md" overwrite="yes" >
            <scale width="75%" height="75%"/>
            <regexpmapper from="^(.*)-hd\.(.*)$$" to="\1-md.\2"/>
 </image>

当我运行此操作时,我最终会遇到此错误:

Error: IOException occurs when search for propriate codecs.
Occurs in: com.sun.media.jai.codec.ImageCodec
java.io.IOException: Bad file descriptor
    at java.io.RandomAccessFile.seek(Native Method)
    at com.sun.media.jai.codec.FileSeekableStream.readPage(FileSeekableStream.java:141)
    at com.sun.media.jai.codec.FileSeekableStream.read(FileSeekableStream.java:181)
    at com.sun.media.jai.codec.SeekableStream.readFully(SeekableStream.java:327)
    at com.sun.media.jai.codec.SeekableStream.readFully(SeekableStream.java:306)
    at com.sun.media.jai.codec.ImageCodec.getDecoderNames(ImageCodec.java:274)
    at com.sun.media.jai.opimage.StreamRIF.create(StreamRIF.java:80)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
    at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1679)
    at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)
    at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
    at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)
    at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
    at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
    at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:810)
    at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
    at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
    at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:810)
    at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
    at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
    at javax.media.jai.JAI.createNS(JAI.java:1103)
    at javax.media.jai.JAI.create(JAI.java:977)
    at javax.media.jai.JAI.create(JAI.java:1672)
    at org.apache.tools.ant.taskdefs.optional.image.Image.processFile(Image.java:320)
    at org.apache.tools.ant.taskdefs.optional.image.Image.processDir(Image.java:253)
    at org.apache.tools.ant.taskdefs.optional.image.Image.execute(Image.java:374)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:809)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:29)
java.lang.RuntimeException: - Unable to render RenderedOp for this operation.
    at org.apache.tools.ant.taskdefs.optional.image.Image.processFile(Image.java:343)
    at org.apache.tools.ant.taskdefs.optional.image.Image.processDir(Image.java:253)
    at org.apache.tools.ant.taskdefs.optional.image.Image.execute(Image.java:374)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:809)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:29)
Caused by: java.lang.RuntimeException: - Unable to render RenderedOp for this operation.
    at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:838)
    at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
    at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
    at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:810)
    at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
    at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
    at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:810)
    at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
    at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
    at javax.media.jai.JAI.createNS(JAI.java:1103)
    at javax.media.jai.JAI.create(JAI.java:977)
    at javax.media.jai.JAI.create(JAI.java:1672)
    at org.apache.tools.ant.taskdefs.optional.image.Image.processFile(Image.java:320)
    ... 24 more

如果我从宽度和高度移除%符号,我最终会得到尺寸合适的图像,但PNG会被拧紧[它们看起来像半透明的黑色层]。 大多数图像都是PNG,我必须使用%。

我在MacOS Lion上使用Apache Ant 1.8.2运行此任务。 Java版本:1.6.0_31

我应该为我的蚂蚁添加一些东西来使其发挥作用吗?

由于

0 个答案:

没有答案