简体   繁体   中英

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.

Java code:

    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:

                <img wicket:id="gif"/>     

EDIT:

Tried martin-g suggestion, gif still doesn't animate

      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) .

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). Please file a ticket in Wicket's JIRA for this improvement! Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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