I am working on a project in which I need to create graphics (bufferedimage) on another image.
I am using ZK framework for Front end and java for back end.
Here is my sample code and output.
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));
}
}
}
Where img is an element id of ZK element Image.
and my ZK code is
<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>
I need to have GIF image(blinking image) on ladle 7. but its not animating please help me through this.
The output is as followsenter image description here