NutzCN Logo
问答 谁用过GraphicsMagic的API啊,同一张图,web上传再去读图片,没问题,而手机上传后再去读,就会读不到文件?
发布于 2778天前 作者 shusheng 1697 次浏览 复制 上一个帖子 下一个帖子
标签:
10:40:43.961 DEBUG (ImageService.java:145) upload - -----second-------ImageServi
ce|upload|e=org.im4java.core.CommandException: java.lang.NullPointerException
        at org.im4java.core.ImageCommand.run(ImageCommand.java:219)
        at net.wendal.nutzbook.util.ImageUtils.waterMark(ImageUtils.java:171)
        at net.wendal.nutzbook.service.image.ImageService.upload(ImageService.ja
va:142)
        at net.wendal.nutzbook.service.image.ImageService.uploadFileList(ImageSe
rvice.java:169)
        at net.wendal.nutzbook.module.forum.ForumModule.images(ForumModule.java:
408)
        at net.wendal.nutzbook.module.forum.ForumModule$$NUTZAOP._aop_invoke(For
umModule.java:1)
        at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77)
        at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57)
        at net.wendal.nutzbook.util.RedisInterceptor.filter(RedisInterceptor.jav
a:25)
        at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
        at net.wendal.nutzbook.module.forum.ForumModule$$NUTZAOP.images(ForumMod
ule.java:1)
        at net.wendal.nutzbook.module.forum.ForumModule$$FASTCLASS._invoke(Forum
Module.java:1)
        at org.nutz.lang.reflect.AbstractFastClass.invoke(AbstractFastClass.java
:143)
        at org.nutz.lang.reflect.FastClassFactory.invoke(FastClassFactory.java:6
7)
        at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvok
eProcessor.java:27)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor
.java:33)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFilt
ersProcessor.java:58)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at org.nutz.integration.shiro.NutShiroProcessor.process(NutShiroProcesso
r.java:126)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.j
ava:123)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcess
or.java:27)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(
UpdateRequestAttributesProcessor.java:15)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at net.wendal.nutzbook.mvc.DailyUniqueUsersProcessor.process(DailyUnique
UsersProcessor.java:48)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcesso
r.java:44)
        at net.wendal.nutzbook.mvc.LogTimeProcessor.process(LogTimeProcessor.jav
a:19)
        at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
        at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:68)
        at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
        at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:165)
        at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:16
8)
        at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:23
3)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:165)
        at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.j
ava:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:165)
        at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(Abstrac
tShiroFilter.java:449)
        at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiro
Filter.java:365)
        at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallab
le.java:90)
        at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable
.java:83)
        at org.apache.shiro.subject.support.DelegatingSubject.execute(Delegating
Subject.java:383)
        at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(Abs
tractShiroFilter.java:362)
        at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerReq
uestFilter.java:125)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:165)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:199)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:474)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:140)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:79)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAcce
ssLogValve.java:624)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:349)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java
:783)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLig
ht.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(Abstract
Protocol.java:745)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpo
int.java:1437)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBas
e.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskTh
read.java:61)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
        at org.im4java.core.ImageCommand.finished(ImageCommand.java:252)
        at org.im4java.process.ProcessStarter.run(ProcessStarter.java:314)
        at org.im4java.core.ImageCommand.run(ImageCommand.java:215)
        ... 69 more
13 回复

ImageUtils的什么东西空指针了

/**
     * 图片水印
     *
     * @param srcImagePath
     *            源图片路径
     * @param destImagePath
     *            目标图片路径
     * @param dissolve
     *            透明度(0-100)
     * @throws Exception
     */
    public static void waterMark(String srcImagePath, String destImagePath, Integer dissolve,
                                 String watermarkImagePath) throws Exception {
        // 原始图片信息
        IMOperation op = new IMOperation();
        op.gravity("southeast");// 位置center:中心;northwest:左上;southeast:右下
        // 水印透明度
        op.dissolve(dissolve);
        // 水印
        op.addImage(watermarkImagePath.substring(watermarkImagePath.indexOf(":")+1));
        // 原图
        op.addImage(srcImagePath);
        // 目标
        op.addImage(destImagePath);
        ImageCommand cmd = new CompositeCmd(true);// 不填true会报错
        String osName = System.getProperty("os.name").toLowerCase();
        if (osName.indexOf("win") >= 0) { // linux下不要设置此值,不然会报错
            cmd.setSearchPath("D:\\install\\GraphicsMagick-1.3.25-Q8");//GraphicsMagick安装路径
        }
        cmd.setErrorConsumer(StandardStream.STDERR);
        cmd.run(op);
    }

@wendal

那就继续翻ImageCommand.java:219行的源码看看,看看啥东西是null了

Caused by: org.im4java.core.CommandException: return code: 1
	at org.im4java.core.ImageCommand.finished(ImageCommand.java:255)
	at org.im4java.process.ProcessStarter.run(ProcessStarter.java:314)
	at org.im4java.core.ImageCommand.run(ImageCommand.java:215)
	... 69 more

导入源码后,将空指针判空以后,就返回错误码1,不知道什么意思
@wendal

 0
down vote
	

It's because ImageMagick's compare will return a non-zero exit code if the images are dissimilar. But the comparison should be working, the resulting difference image (3rd argument) is correctly generated.

It's however a problem for im4java because that's considered an error exit code, and there's no way as far as I know to tell im4java that it's not. See this discussion for more details.

You can work around it by catching the exception and ignoring it if the return code was 1 (compare should return 2 in case of error).

似乎是让我忽略此异常的意思
@wendal

具体的源码是啥, 要搞清楚为啥是null,而不是简单跳过

  protected void finished(int pReturnCode) throws Exception {
    if (pReturnCode > 0) {
      CommandException ce;
      if (iErrorText != null && iErrorText.size() > 0) {
	ce = new CommandException(iErrorText.get(0));
      } else {
	ce = new CommandException("return code: " + pReturnCode);
      }
      ce.setErrorText(iErrorText);
      ce.setReturnCode(pReturnCode);
      throw ce;
    } else {
      removeTmpFiles();
    }
  }

iErrorText 这个为空了

是不是那图片根本读不了?? 测的是同一个图片文件吗?

是的,就是同一张图片哦,只是从手机上传到电脑上,用JSP传到服务器上都没有问题,用手机直接上传服务器后就有问题,而且调用的是我这边的同一个接口哦
@wendal

把文件的md5算一下,对比一下

找到问题的原因了,Android端对比较大的图片进行了压缩,估计是压缩的API丢失了某些数据导致的,iOS端对较大的图片文件也会进行图片压缩,但是iOS上传上来的问题都很正常

添加回复
请先登陆
回到顶部