1 58 package org.krysalis.barcode.output.bitmap; 59 60 import java.awt.image.BufferedImage ; 61 import java.io.IOException ; 62 import java.io.OutputStream ; 63 64 import org.krysalis.barcode.BarcodeDimension; 65 import org.krysalis.barcode.output.AbstractCanvasProvider; 66 import org.krysalis.barcode.output.java2d.Java2DCanvasProvider; 67 68 74 public class BitmapCanvasProvider extends AbstractCanvasProvider { 75 76 private OutputStream out; 77 private String mime; 78 private int resolution; 79 private int imageType; 80 private boolean antiAlias; 81 private BufferedImage image; 82 private Java2DCanvasProvider delegate; 83 84 92 public BitmapCanvasProvider(OutputStream out, String mime, 93 int resolution, int imageType, boolean antiAlias) { 94 super(); 95 this.out = out; 96 this.mime = mime; 97 this.resolution = resolution; 98 this.imageType = imageType; 99 this.antiAlias = antiAlias; 100 } 101 102 108 public BitmapCanvasProvider(int resolution, int imageType, boolean antiAlias) { 109 this(null, null, resolution, imageType, antiAlias); 110 } 111 112 117 public void finish() throws IOException { 118 this.image.flush(); 119 if (this.out != null) { 120 final BitmapEncoder encoder = BitmapEncoderRegistry.getInstance(mime); 121 encoder.encode(this.image, out, mime, resolution); 122 } 123 } 124 125 129 public BufferedImage getBufferedImage() { 130 return this.image; 131 } 132 133 134 public void establishDimensions(BarcodeDimension dim) { 135 super.establishDimensions(dim); 136 this.image = BitmapBuilder.prepareImage(dim, this.resolution, this.imageType); 137 this.delegate = new Java2DCanvasProvider( 138 BitmapBuilder.prepareGraphics2D(this.image, dim, this.antiAlias)); 139 this.delegate.establishDimensions(dim); 140 } 141 142 143 public void deviceFillRect(double x, double y, double w, double h) { 144 this.delegate.deviceFillRect(x, y, w, h); 145 } 146 147 148 public void deviceJustifiedText(String text, 149 double x1, double x2, double y1, 150 String fontName, double fontSize) { 151 this.delegate.deviceJustifiedText(text, x1, x2, y1, fontName, fontSize); 152 } 153 154 155 public void deviceCenteredText(String text, 156 double x1, double x2, double y1, 157 String fontName, double fontSize) { 158 this.delegate.deviceCenteredText(text, x1, x2, y1, fontName, fontSize); 159 } 160 161 } 162 | Popular Tags |