Skip to content

Instantly share code, notes, and snippets.

@thieunguyenhung
Last active August 7, 2019 08:23
Show Gist options
  • Save thieunguyenhung/ad676a7a182882af09c423d7b21be9de to your computer and use it in GitHub Desktop.
Save thieunguyenhung/ad676a7a182882af09c423d7b21be9de to your computer and use it in GitHub Desktop.
Example how to convert BitMatrix to SVG file
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