mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Fix a typo and add better javadoc
git-svn-id: https://zxing.googlecode.com/svn/trunk@1096 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
2cc7a2c8fa
commit
a853429282
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package com.google.zxing.client.j2se;
|
package com.google.zxing.client.j2se;
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
|
||||||
import com.google.zxing.MultiFormatWriter;
|
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
import com.google.zxing.common.ByteMatrix;
|
import com.google.zxing.common.ByteMatrix;
|
||||||
|
|
||||||
|
@ -26,11 +24,11 @@ import java.io.File;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.Hashtable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a {@link BitMatrix} or {@link ByteMatrix} to {@link BufferedImage}, file or stream.
|
* Writes a {@link BitMatrix} or {@link ByteMatrix} to {@link BufferedImage},
|
||||||
* Provided here instead of core since it depends on Java SE libraries.
|
* file or stream. Provided here instead of core since it depends on
|
||||||
|
* Java SE libraries.
|
||||||
*
|
*
|
||||||
* @author Sean Owen
|
* @author Sean Owen
|
||||||
*/
|
*/
|
||||||
|
@ -41,6 +39,10 @@ public final class MatrixToImageWriter {
|
||||||
|
|
||||||
private MatrixToImageWriter() {}
|
private MatrixToImageWriter() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a {@link BitMatrix} as an image, where "false" bits are rendered
|
||||||
|
* as white, and "true" bits are rendered as black.
|
||||||
|
*/
|
||||||
public static BufferedImage toBufferedImage(BitMatrix matrix) {
|
public static BufferedImage toBufferedImage(BitMatrix matrix) {
|
||||||
int width = matrix.getWidth();
|
int width = matrix.getWidth();
|
||||||
int height = matrix.getHeight();
|
int height = matrix.getHeight();
|
||||||
|
@ -53,6 +55,13 @@ public final class MatrixToImageWriter {
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a {@link ByteMatrix} as an image, as a
|
||||||
|
* {@link BufferedImage}. The byte values are construed as (unsigned)
|
||||||
|
* luminance values, in theory.
|
||||||
|
* However, anything but 0 will be rendered as white, and 0 will be
|
||||||
|
* rendered as black.
|
||||||
|
*/
|
||||||
public static BufferedImage toBufferedImage(ByteMatrix matrix) {
|
public static BufferedImage toBufferedImage(ByteMatrix matrix) {
|
||||||
int width = matrix.getWidth();
|
int width = matrix.getWidth();
|
||||||
int height = matrix.getHeight();
|
int height = matrix.getHeight();
|
||||||
|
@ -65,24 +74,44 @@ public final class MatrixToImageWriter {
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a {@link BitMatrix} to a file.
|
||||||
|
*
|
||||||
|
* @see #toBufferedImage(BitMatrix)
|
||||||
|
*/
|
||||||
public static void writeToFile(BitMatrix matrix, String format, File file)
|
public static void writeToFile(BitMatrix matrix, String format, File file)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
BufferedImage image = toBufferedImage(matrix);
|
BufferedImage image = toBufferedImage(matrix);
|
||||||
ImageIO.write(image, format, file);
|
ImageIO.write(image, format, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a {@link ByteMatrix} to a file.
|
||||||
|
*
|
||||||
|
* @see #toBufferedImage(ByteMatrix)
|
||||||
|
*/
|
||||||
public static void writeToFile(ByteMatrix matrix, String format, File file)
|
public static void writeToFile(ByteMatrix matrix, String format, File file)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
BufferedImage image = toBufferedImage(matrix);
|
BufferedImage image = toBufferedImage(matrix);
|
||||||
ImageIO.write(image, format, file);
|
ImageIO.write(image, format, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a {@link BitMatrix} to a stream.
|
||||||
|
*
|
||||||
|
* @see #toBufferedImage(BitMatrix)
|
||||||
|
*/
|
||||||
public static void writeToStream(BitMatrix matrix, String format, OutputStream stream)
|
public static void writeToStream(BitMatrix matrix, String format, OutputStream stream)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
BufferedImage image = toBufferedImage(matrix);
|
BufferedImage image = toBufferedImage(matrix);
|
||||||
ImageIO.write(image, format, stream);
|
ImageIO.write(image, format, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a {@link ByteMatrix} to a stream.
|
||||||
|
*
|
||||||
|
* @see #toBufferedImage(ByteMatrix)
|
||||||
|
*/
|
||||||
public static void writeToStream(ByteMatrix matrix, String format, OutputStream stream)
|
public static void writeToStream(ByteMatrix matrix, String format, OutputStream stream)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
BufferedImage image = toBufferedImage(matrix);
|
BufferedImage image = toBufferedImage(matrix);
|
||||||
|
|
Loading…
Reference in a new issue