Last active
August 7, 2019 08:23
-
-
Save thieunguyenhung/ad676a7a182882af09c423d7b21be9de to your computer and use it in GitHub Desktop.
Example how to convert BitMatrix to SVG file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.zxing.common.BitMatrix; | |
import org.jfree.graphics2d.svg.SVGGraphics2D; | |
import org.jfree.graphics2d.svg.SVGUtils; | |
import java.awt.*; | |
import java.io.File; | |
import java.io.IOException; | |
//..... | |
private void bitMatrixToSVG(BitMatrix bitMatrix, File outputFileSVG) throws IOException { | |
int matrixWidth = bitMatrix.getWidth(); | |
int matrixHeight = bitMatrix.getHeight(); | |
SVGGraphics2D g2 = new SVGGraphics2D(matrixWidth, matrixWidth); | |
g2.setColor(Color.BLACK); | |
for (int i = 0; i < matrixWidth; i++) { | |
for (int j = 0; j < matrixHeight; j++) { | |
if (bitMatrix.get(i, j)) { | |
g2.fillRect(i, j, 1, 1); | |
} | |
} | |
} | |
SVGUtils.writeToSVG(outputFileSVG, g2.getSVGElement()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment