Gif不是通过缓冲图像制作动画

时间:2017-04-18 12:57:32

标签: java javax.imageio

我正在开展一个项目,我需要在另一个图像上创建图形(bufferedimage)。

我正在使用前端的ZK框架和后端的java。

这是我的示例代码和输出。

public void createImage() throws Exception{ 
        ladleList = fD.getListLocation();

        baseImage = ImageIO.read(new File(BASE_IMG));

        Graphics2D baseGraphics = baseImage.createGraphics();

        for(LtsLadleLocation ladLoc : ladleList){

            setLadlePostion(ladLoc);
            setLadleImage(ladle);           

            Graphics2D imageGraphics = ladleImage.createGraphics();     
            imageGraphics.setFont(font);

            String ladleNo  = ladle.getLadleId().intValue() <=9 ? " "+ladle.getLadleId().toString() : ladle.getLadleId().toString();

            imageGraphics.drawString(ladleNo, 12, 45);
            baseGraphics.drawImage(ladleImage, position.getxVal(), position.getyVal(), 62,62,null,null);

            img.setContent(baseImage);          

            BindUtils.postNotifyChange(null, null, this, "img");

            ladle=null;
            position = null;
            ladleImage = null;          
        }
    }   


    /**
     * @Desc : selects the ladle and position values from the Position List.
     *          posList is having x and y values for particular locations.
     * @param : ladLoc and position
     */
    public void setLadlePostion(LtsLadleLocation ladLoc) {
        for(Position pos:posList){
            if(ladLoc.getLocationdescription().equalsIgnoreCase(pos.getLocName())){
                ladle = ladLoc;
                position = pos;
                break;          
            }
        }
    }

    /**
     * @Desc : This method is used to get the relevent image according to the location
     *          and according to the status.
     * @param ladle2
     */
    public void setLadleImage(LtsLadleLocation ladleImageObj) throws Exception {    
        if("LF_2".equalsIgnoreCase(ladleImageObj.getLocationdescription())){
            setLFLadle(ladleImageObj);
        }else{
            setNormalLadle(ladleImageObj);
        }
    }

    /**
     * @Desc : This method is used to set the normal ladle images (Circle Shaped images)
     * @param ladleImageObj
     */
    public void setNormalLadle(LtsLadleLocation ladleImageObj) throws Exception {
            if("OUT".equalsIgnoreCase(ladleImageObj.getStatus())){
                ladleImage = ImageIO.read(new File(HEATER_OUT));
            }else if("IN".equalsIgnoreCase(ladleImageObj.getStatus())){
                if("F".equalsIgnoreCase(ladleImageObj.getLadleStatusFlag())){
                    ladleImage = ImageIO.read(new File(HEATER_FILLED));
                }else{
                    ladleImage = ImageIO.read(new File(HEATER_EMPTY));
                }
            }       
    }

    /**
     * @Desc : For Setting LF images
     * @param ladleImageObj
     */
    public void setLFLadle(LtsLadleLocation ladleImageObj) throws Exception {
            if("OUT".equalsIgnoreCase(ladleImageObj.getStatus())){
                ladleImage = ImageIO.read(new File(LADLE_OUT));
            }else if("IN".equalsIgnoreCase(ladleImageObj.getStatus())){
                if("F".equalsIgnoreCase(ladleImageObj.getLadleStatusFlag())){
                    ladleImage = ImageIO.read(new File(LADLE_FILLED));
                }else{
                    ladleImage = ImageIO.read(new File(LADLE_EMPTY));
                }
            }       
    }

其中img是ZK元素Image的元素id。

我的ZK代码是

<window title="Hello World!!" border="normal" apply="org.zkoss.bind.BindComposer"
viewModel = "@id('vm') @init('com.practice.image.ImageViewModel')">
    <image id="img" >
        <custom-attributes org.zkoss.zul.image.preload="true" />
    </image>
    <timer id="refresh" repeats="true" onTimer="@command('createImage')" delay="10000"/>    
</window>

我需要在钢包7上有GIF图像(闪烁的图像)但是它没有动画请帮我解决这个问题。

输出如下enter image description here

0 个答案:

没有答案