import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.*; public class ReadWatermark { static final int pWidth=352; // Pattern width static final int pHeight=240; // Pattern height static final int pxWidth=4; // Bit width static final int pxHeight=5; // Bit height static final int bWidth=88; // Bits table width static final int bHeight=48; // Bits table height static final int Black=0xFF000000; // Black = 0 static final int White=0xFFFFFFFF; // White = 1 static final String filenameSrc = "pattern.bmp"; // Stores the filename public static byte[][] getPatternBits(BufferedImage image) { byte barcode[][] = new byte[bWidth][bHeight]; // Stores the bits for (int y=0, i=0; y<pWidth; y+=pxWidth, i++) for (int x=0, j=0; x<pHeight; x+=pxHeight, j++) if (image.getRGB(y+1,x)==Black) // we check y+1 to target correctly (see pattern) barcode[i][j]=0; // got black else barcode[i][j]=1; // got white return barcode; } public static BufferedImage readImage(File file) { try { return (ImageIO.read(file)); } catch (IOException e) { return (null); } } public static void main(String[] args) { byte barcode[][]; // Stores the bits File fileSrc = new File(filenameSrc); // Create file reference BufferedImage imageSrc=readImage(fileSrc); // Read file if (imageSrc==null) System.exit(1); // no file found barcode=getPatternBits(imageSrc); // Get bits for (int i=bWidth-1; i>=0; i--) { // Print the pattern (1 row here is 1 column there, right to left) for (int j=bHeight-1; j>=0; j--) System.out.print(barcode[i][j]); System.out.println(); } } }
/console SET screenshotQuality "9"
Source: https://habr.com/ru/post/151297/
All Articles