Example Render Aztec Code

From BoofCV
Revision as of 16:31, 2 September 2022 by Peter (talk | contribs) (Created page with "<center> <gallery widths=400px heights=400px> File:Example_render_aztec_code.png | Rendered Aztec Code from this example </gallery> </center> This example shows how a [https:...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This example shows how a Aztec Codes can be rendered into an image. Its easy to adapt the approach here for just about any file format, e.g. PDF.

Example Code:

Concepts:

  • Fiducials
  • Micro QR Codes

Relevant Examples/Tutorials:

Example Code

/**
 * An easy-to-use API is provided for creating your own Aztec Code marker. You can render it as an image or PDF
 * document.
 *
 * @author Peter Abeles
 * @see MicroQrCodeGenerator
 */
public class ExampleRenderAztecCode {
	public static void main( String[] args ) {
		// Create a marker to render. Almost everything about how the marker is constructed can be manually specified
		// or you can let it automatically select everything
		AztecCode marker = new AztecEncoder().addAutomatic("Code 2D!").fixate();
		// NOTE: The final function you call must be fixate(), that's how it knows it's done

		// Render the marker as an image. It's also possible to render as a PDF or your own custom format
		GrayU8 rendered = AztecGenerator.renderImage(/* pixel per square */ 10, /* border squares */ 1, marker);

		// Convert it to a BufferedImage for display purposes
		BufferedImage output = ConvertBufferedImage.convertTo(rendered, null);

		// You can also save it to disk by uncommenting the line below
//		UtilImageIO.saveImage(output, "aztec.png");

		// Display the rendered marker
		ShowImages.showWindow(output, "Rendered Aztec Code", true);
	}
}