简体   繁体   English

页面中外部资源的GIF在apache wicket Web应用程序中未设置动画

[英]GIF from external resource in page is not animating in apache wicket web application

I am using external images in my webaplication, everything wass fine until I wanted to add animated gif there, the gif loads, but it doesn't animate. 我在网络应用程序中使用外部图像,一切都很好,直到我想在那里添加动画gif,gif加载完毕,但它没有动画。

Java code: Java代码:

    File sourceimage = new File("loading_img.gif");

    try {
        final BufferedDynamicImageResource r = new BufferedDynamicImageResource("GIF");
        r.setImage(ImageIO.read(sourceimage));
        add(new Image("gif",  r));

    } catch (Exception e) {
        e.printStackTrace();
    }

HTML: HTML:

                <img wicket:id="gif"/>     

EDIT: 编辑:

Tried martin-g suggestion, gif still doesn't animate 尝试使用Martin-G建议,GIF仍然没有动画

      try {
          final BufferedDynamicImageResource r = new BufferedDynamicImageResource("GIF"){
              @Override
              protected void setResponseHeaders(AbstractResource.ResourceResponse data,
                      IResource.Attributes attributes){
                  super.setResponseHeaders(data, attributes);
                  data.setContentType("image/gif");
              }
              };
          r.setImage(ImageIO.read(sourceimage));
          add(new Image("gif",  r));

      } catch (Exception e) {
          e.printStackTrace();
      }

The problem is that the content type is not automatically set. 问题是内容类型没有自动设置。 You will need to override org.apache.wicket.request.resource.AbstractResource#setResponseHeaders() and set with via resourceResponse.setContentType(String) . 您将需要重写org.apache.wicket.request.resource.AbstractResource#setResponseHeaders()并通过resourceResponse.setContentType(String)

Maybe this should be done automatically by Wicket in org.apache.wicket.request.resource.DynamicImageResource, since it knows the format ("png", or "gif" as in your case). 也许应该由Wicket在org.apache.wicket.request.resource.DynamicImageResource中自动完成,因为它知道格式(如您的情况那样为“ png”或“ gif”)。 Please file a ticket in Wicket's JIRA for this improvement! 请为此改进在Wicket的JIRA中提交票证! Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM