This tutorial shows how to burn annotations inside an
AnnContainer onto an image in a Java application using the LEADTOOLS SDK.
|Summary||This tutorial covers burning annotations to an image in a Java application.|
|Completion Time||30 minutes|
|Project||Download tutorial project (1 MB)|
|IDE||Eclipse / IntelliJ|
|Runtime License||Download LEADTOOLS|
|Try it in another language|
Get familiar with the basic steps of creating a project by reviewing the Add References and Set a License tutorial, before working on the Burn Annotations to an Image - Java tutorial.
Start with a copy of the project created in the Add References and Set a License tutorial. If that project is unavailable, follow the steps in that tutorial to create it.
The references needed depend upon the purpose of the project. References can be added by local
.jar files located at
For this project, the following references are needed:
For a complete list of which JAR files are required for your application, refer to Files to be Included with your Java Application
The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.
There are two types of runtime licenses:
Adding LEADTOOLS references and setting a license are covered in more detail in the Add References and Set a License tutorial.
With the project created, the references added, and the license set, coding can begin.
_Main.java class in the Package Explorer. Add the following statements to the
import block at the top.
main() method, add the following to set the library path to where the C DLL files are located, as well as load the LEADTOOLS libraries that were previously imported.
public static void main(String args) throws IOException
Add a new method to the
_Main class called
burnAnnotationsToImage and call it inside the
main() method after the
SetLicense() call, as shown above.
Add the code below to the
burnAnnotationsToImage() method to load annotations from a file and burn them to the loaded image.
static void burnAnnotationsToImage() throws FileNotFoundException
String imageFile = "FILE PATH TO IMAGE FILE";
String annFile = "FILE PATH TO XML FILE CONTAINING ANNOTATIONS";
String outputFile = "FILE PATH TO OUTPUT TO";
AnnJavaRenderingEngine _renderingEngine = new AnnJavaRenderingEngine();
RasterCodecs codecs = new RasterCodecs();
AnnCodecs annCodecs = new AnnCodecs();
AnnContainer container = new AnnContainer();
RasterImage srcImage = codecs.load(imageFile);
container.getMapper().mapResolutions(srcImage.getXResolution(), srcImage.getYResolution(), srcImage.getXResolution(), srcImage.getYResolution());
InputStream stream = new FileInputStream(annFile);
container = annCodecs.load(stream, 1);
RasterImage burnImage = _renderingEngine.renderOnImage(container, srcImage);
codecs.save(burnImage, outputFile, RasterImageFormat.JPEG, 0);
Run the project by pressing Ctrl + F11, or by selecting Run -> Run.
If the steps are followed correctly, the application loads the specified image as a
RasterImage, loads the annotations contained in an XML file to an
AnnContainer, and then burns those annotations to the image and exports that image to a file.
This tutorial showed how to add the necessary references and code to burn annotations to an image. Also, it covered how to use the