Clarified and simplified some code.

pull/134/head
Project Nayuki 6 years ago
parent b7f8d3a239
commit 593ff051bf

@ -185,8 +185,8 @@ public final class QrCode {
BufferedImage result = new BufferedImage((size + border * 2) * scale, (size + border * 2) * scale, BufferedImage.TYPE_INT_RGB);
for (int y = 0; y < result.getHeight(); y++) {
for (int x = 0; x < result.getWidth(); x++) {
boolean val = getModule(x / scale - border, y / scale - border);
result.setRGB(x, y, val ? 0x000000 : 0xFFFFFF);
boolean color = getModule(x / scale - border, y / scale - border);
result.setRGB(x, y, color ? 0x000000 : 0xFFFFFF);
}
}
return result;

@ -28,11 +28,9 @@ package io.nayuki.fastqrcodegen;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import javax.imageio.ImageIO;
@ -64,11 +62,8 @@ public final class QrCodeGeneratorDemo {
ImageIO.write(img, "png", imgFile); // Write image to file
String svg = qr.toSvgString(4); // Convert to SVG XML code
try (Writer out = new OutputStreamWriter(
new FileOutputStream("hello-world-QR.svg"),
StandardCharsets.UTF_8)) {
out.write(svg); // Create/overwrite file and write SVG data
}
Files.write(new File("hello-world-QR.svg").toPath(),
svg.getBytes(StandardCharsets.UTF_8));
}

@ -174,7 +174,8 @@ final class QrTemplate {
// Draw two copies
for (int i = 0; i < 18; i++) {
int bit = (bits >>> i) & 1;
int a = size - 11 + i % 3, b = i / 3;
int a = size - 11 + i % 3;
int b = i / 3;
darkenFunctionModule(a, b, bit);
darkenFunctionModule(b, a, bit);
}

Loading…
Cancel
Save