Il giorno lunedì 7 maggio 2018 15:54:00 UTC+2,
sblen...@gmail.com ha scritto:
> Printing text is quite simple.
You can also print graphics. This is an example of what you can do:
https://imgur.com/a/gyxkkqk
I did it writing a simple "driver" in Java that converts images (for now in black and white, with white background) into commands for the Commodore MPS 803 printer:
package eu.sblendorio;
import javax.imageio.ImageIO;
import java.awt.image.*;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
if (args.length == 0) System.exit(1);
final String filename = args[0];
File f = new File(filename);
BufferedImage bi = ImageIO.read(f);
print(bi);
}
static int getPixel(BufferedImage bi, int x, int y) {
final int w = bi.getWidth();
final int h = bi.getHeight();
if (x >= w || y >= h || x < 0 || y < 0)
return 0;
final boolean pixel = bi.getRGB(x, y) != -1;
return pixel ? 1 : 0;
}
static void print(BufferedImage bi) {
final int pow[] = {1, 2, 4, 8, 16, 32, 64};
final int w = bi.getWidth();
final int h = bi.getHeight();
int rows = h / 7 + (h % 7 == 0 ? 0 : 1);
System.out.write(8);
for (int row=0; row<rows; ++row) {
for (int x=0; x<w; ++x) {
int code = 128;
for (int dy=0; dy<7; ++dy) {
final int pixel = getPixel(bi, x,(row * 7) + dy);
code += pow[dy]*pixel;
}
System.out.write(code);
}
System.out.write(13);
}
System.out.write(15);
System.out.write(13);
}
}