java.awt.image.MemoryImageSource Java Examples
The following examples show how to use
java.awt.image.MemoryImageSource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BarcodeDatamatrix.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates a <CODE>java.awt.Image</CODE>. A successful call to the method <CODE>generate()</CODE> * before calling this method is required. * @param foreground the color of the bars * @param background the color of the background * @return the image */ public java.awt.Image createAwtImage(Color foreground, Color background) { if (image == null) return null; int f = foreground.getRGB(); int g = background.getRGB(); Canvas canvas = new Canvas(); int w = width + 2 * ws; int h = height + 2 * ws; int pix[] = new int[w * h]; int stride = (w + 7) / 8; int ptr = 0; for (int k = 0; k < h; ++k) { int p = k * stride; for (int j = 0; j < w; ++j) { int b = image[p + (j / 8)] & 0xff; b <<= j % 8; pix[ptr++] = (b & 0x80) == 0 ? g : f; } } java.awt.Image img = canvas.createImage(new MemoryImageSource(w, h, pix, 0, w)); return img; }
Example #2
Source File: XYZApp.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private void Setup() { balls = new Image[nBalls]; byte red[] = new byte[256]; red[0] = (byte) bgGrey; byte green[] = new byte[256]; green[0] = (byte) bgGrey; byte blue[] = new byte[256]; blue[0] = (byte) bgGrey; for (int r = 0; r < nBalls; r++) { float b = (float) (r + 1) / nBalls; for (int i = maxr; i >= 1; --i) { float d = (float) i / maxr; red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b); green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b); blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b); } IndexColorModel model = new IndexColorModel(8, maxr + 1, red, green, blue, 0); balls[r] = applet.createImage( new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2)); } }
Example #3
Source File: ImageTransferTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static Image createImage() { int w = 100; int h = 100; int[] pix = new int[w * h]; int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red = 127; int green = 127; int blue = y > h / 2 ? 127 : 0; int alpha = 255; if (x < w / 4 && y < h / 4) { alpha = 0; red = 0; } pix[index++] = (alpha << 24) | (red << 16) | (green << 8) | blue; } } return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pix, 0, w)); }
Example #4
Source File: XYZApp.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private void Setup() { balls = new Image[nBalls]; byte red[] = new byte[256]; red[0] = (byte) bgGrey; byte green[] = new byte[256]; green[0] = (byte) bgGrey; byte blue[] = new byte[256]; blue[0] = (byte) bgGrey; for (int r = 0; r < nBalls; r++) { float b = (float) (r + 1) / nBalls; for (int i = maxr; i >= 1; --i) { float d = (float) i / maxr; red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b); green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b); blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b); } IndexColorModel model = new IndexColorModel(8, maxr + 1, red, green, blue, 0); balls[r] = applet.createImage( new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2)); } }
Example #5
Source File: XYZApp.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private void Setup() { balls = new Image[nBalls]; byte red[] = new byte[256]; red[0] = (byte) bgGrey; byte green[] = new byte[256]; green[0] = (byte) bgGrey; byte blue[] = new byte[256]; blue[0] = (byte) bgGrey; for (int r = 0; r < nBalls; r++) { float b = (float) (r + 1) / nBalls; for (int i = maxr; i >= 1; --i) { float d = (float) i / maxr; red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b); green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b); blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b); } IndexColorModel model = new IndexColorModel(8, maxr + 1, red, green, blue, 0); balls[r] = applet.createImage( new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2)); } }
Example #6
Source File: GraphicsUtils.java From RipplePower with Apache License 2.0 | 6 votes |
/** * 将黑色颜色部分透明化 * * @param img * @return */ final static public Image transparencyBlackColor(final Image img) { int width = img.getWidth(null); int height = img.getHeight(null); PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, true); try { pg.grabPixels(); } catch (InterruptedException e) { e.printStackTrace(); } int pixels[] = (int[]) pg.getPixels(); int length = pixels.length; for (int i = 0; i < length; i++) { if (pixels[i] == 0) { pixels[i] = 0xffffff; } } return toolKit.createImage(new MemoryImageSource(width, height, pixels, 0, width)); }
Example #7
Source File: GraphicsUtils.java From RipplePower with Apache License 2.0 | 6 votes |
final static public Image transparencyBlackColor(final Image img, final Color c) { int width = img.getWidth(null); int height = img.getHeight(null); PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, true); try { pg.grabPixels(); } catch (InterruptedException e) { e.printStackTrace(); } int pixels[] = (int[]) pg.getPixels(); int length = pixels.length; for (int i = 0; i < length; i++) { int pixel = pixels[i]; int[] rgbs = LColor.getRGBs(pixel); if (rgbs[0] >= 252 && rgbs[1] >= 252 && rgbs[1] >= 252) { pixels[i] = 0xffffff; } } return toolKit.createImage(new MemoryImageSource(width, height, pixels, 0, width)); }
Example #8
Source File: TestImage.java From libreveris with GNU Lesser General Public License v3.0 | 6 votes |
public static Image decodeImage (String[] rows) { final int width = rows[0].length(); final int height = rows.length; int[] pix = new int[width * height]; int index = 0; for (String row : rows) { for (int x = 0; x < width; x++) { pix[index++] = decodeARGB (row.charAt (x)); } } // Create the proper image icon Toolkit tk = Toolkit.getDefaultToolkit (); return tk.createImage (new MemoryImageSource (width, height, pix, 0, width)); }
Example #9
Source File: ImageTransferTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static Image createImage() { int w = 100; int h = 100; int[] pix = new int[w * h]; int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red = 127; int green = 127; int blue = y > h / 2 ? 127 : 0; int alpha = 255; if (x < w / 4 && y < h / 4) { alpha = 0; red = 0; } pix[index++] = (alpha << 24) | (red << 16) | (green << 8) | blue; } } return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pix, 0, w)); }
Example #10
Source File: XYZApp.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private void Setup() { balls = new Image[nBalls]; byte red[] = new byte[256]; red[0] = (byte) bgGrey; byte green[] = new byte[256]; green[0] = (byte) bgGrey; byte blue[] = new byte[256]; blue[0] = (byte) bgGrey; for (int r = 0; r < nBalls; r++) { float b = (float) (r + 1) / nBalls; for (int i = maxr; i >= 1; --i) { float d = (float) i / maxr; red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b); green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b); blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b); } IndexColorModel model = new IndexColorModel(8, maxr + 1, red, green, blue, 0); balls[r] = applet.createImage( new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2)); } }
Example #11
Source File: ImageTransferTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static Image createImage() { int w = 100; int h = 100; int[] pix = new int[w * h]; int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red = 127; int green = 127; int blue = y > h / 2 ? 127 : 0; int alpha = 255; if (x < w / 4 && y < h / 4) { alpha = 0; red = 0; } pix[index++] = (alpha << 24) | (red << 16) | (green << 8) | blue; } } return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pix, 0, w)); }
Example #12
Source File: ImageTransferTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private static Image createImage() { int w = 100; int h = 100; int[] pix = new int[w * h]; int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red = 127; int green = 127; int blue = y > h / 2 ? 127 : 0; int alpha = 255; if (x < w / 4 && y < h / 4) { alpha = 0; red = 0; } pix[index++] = (alpha << 24) | (red << 16) | (green << 8) | blue; } } return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pix, 0, w)); }
Example #13
Source File: XYZApp.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private void Setup() { balls = new Image[nBalls]; byte red[] = new byte[256]; red[0] = (byte) bgGrey; byte green[] = new byte[256]; green[0] = (byte) bgGrey; byte blue[] = new byte[256]; blue[0] = (byte) bgGrey; for (int r = 0; r < nBalls; r++) { float b = (float) (r + 1) / nBalls; for (int i = maxr; i >= 1; --i) { float d = (float) i / maxr; red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b); green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b); blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b); } IndexColorModel model = new IndexColorModel(8, maxr + 1, red, green, blue, 0); balls[r] = applet.createImage( new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2)); } }
Example #14
Source File: XYZApp.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private void Setup() { balls = new Image[nBalls]; byte red[] = new byte[256]; red[0] = (byte) bgGrey; byte green[] = new byte[256]; green[0] = (byte) bgGrey; byte blue[] = new byte[256]; blue[0] = (byte) bgGrey; for (int r = 0; r < nBalls; r++) { float b = (float) (r + 1) / nBalls; for (int i = maxr; i >= 1; --i) { float d = (float) i / maxr; red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b); green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b); blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b); } IndexColorModel model = new IndexColorModel(8, maxr + 1, red, green, blue, 0); balls[r] = applet.createImage( new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2)); } }
Example #15
Source File: ImageTransferTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static Image createImage() { int w = 100; int h = 100; int[] pix = new int[w * h]; int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red = 127; int green = 127; int blue = y > h / 2 ? 127 : 0; int alpha = 255; if (x < w / 4 && y < h / 4) { alpha = 0; red = 0; } pix[index++] = (alpha << 24) | (red << 16) | (green << 8) | blue; } } return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pix, 0, w)); }
Example #16
Source File: StarRater.java From mars-sim with GNU General Public License v3.0 | 6 votes |
/** * Converts a byte array to an image that has previously been converted with imageToCompressedByteArray(Image image). * The image is not recognizable as image from standard tools. * * @param data The image. * @return The image. */ public static Image compressedByteArrayToImage(byte[] data) { try { // unzip data ByteArrayInputStream byteStream = new ByteArrayInputStream(data); GZIPInputStream zippedStream = new GZIPInputStream(byteStream); ObjectInputStream objectStream = new ObjectInputStream(zippedStream); int width = objectStream.readShort(); int height = objectStream.readShort(); int[] imageSource = (int[])objectStream.readObject(); objectStream.close(); // create image MemoryImageSource mis = new MemoryImageSource(width, height, imageSource, 0, width); return Toolkit.getDefaultToolkit().createImage(mis); } catch (Exception e) { return null; } }
Example #17
Source File: XYZApp.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private void Setup() { balls = new Image[nBalls]; byte red[] = new byte[256]; red[0] = (byte) bgGrey; byte green[] = new byte[256]; green[0] = (byte) bgGrey; byte blue[] = new byte[256]; blue[0] = (byte) bgGrey; for (int r = 0; r < nBalls; r++) { float b = (float) (r + 1) / nBalls; for (int i = maxr; i >= 1; --i) { float d = (float) i / maxr; red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b); green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b); blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b); } IndexColorModel model = new IndexColorModel(8, maxr + 1, red, green, blue, 0); balls[r] = applet.createImage( new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2)); } }
Example #18
Source File: ImageTransferTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static Image createImage() { int w = 100; int h = 100; int[] pix = new int[w * h]; int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red = 127; int green = 127; int blue = y > h / 2 ? 127 : 0; int alpha = 255; if (x < w / 4 && y < h / 4) { alpha = 0; red = 0; } pix[index++] = (alpha << 24) | (red << 16) | (green << 8) | blue; } } return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pix, 0, w)); }
Example #19
Source File: ImageTransferTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private static Image createImage() { int w = 100; int h = 100; int[] pix = new int[w * h]; int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red = 127; int green = 127; int blue = y > h / 2 ? 127 : 0; int alpha = 255; if (x < w / 4 && y < h / 4) { alpha = 0; red = 0; } pix[index++] = (alpha << 24) | (red << 16) | (green << 8) | blue; } } return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pix, 0, w)); }
Example #20
Source File: XYZApp.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private void Setup() { balls = new Image[nBalls]; byte red[] = new byte[256]; red[0] = (byte) bgGrey; byte green[] = new byte[256]; green[0] = (byte) bgGrey; byte blue[] = new byte[256]; blue[0] = (byte) bgGrey; for (int r = 0; r < nBalls; r++) { float b = (float) (r + 1) / nBalls; for (int i = maxr; i >= 1; --i) { float d = (float) i / maxr; red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b); green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b); blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b); } IndexColorModel model = new IndexColorModel(8, maxr + 1, red, green, blue, 0); balls[r] = applet.createImage( new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2)); } }
Example #21
Source File: XYZApp.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private void Setup() { balls = new Image[nBalls]; byte red[] = new byte[256]; red[0] = (byte) bgGrey; byte green[] = new byte[256]; green[0] = (byte) bgGrey; byte blue[] = new byte[256]; blue[0] = (byte) bgGrey; for (int r = 0; r < nBalls; r++) { float b = (float) (r + 1) / nBalls; for (int i = maxr; i >= 1; --i) { float d = (float) i / maxr; red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b); green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b); blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b); } IndexColorModel model = new IndexColorModel(8, maxr + 1, red, green, blue, 0); balls[r] = applet.createImage( new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2)); } }
Example #22
Source File: XYZApp.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private void Setup() { balls = new Image[nBalls]; byte red[] = new byte[256]; red[0] = (byte) bgGrey; byte green[] = new byte[256]; green[0] = (byte) bgGrey; byte blue[] = new byte[256]; blue[0] = (byte) bgGrey; for (int r = 0; r < nBalls; r++) { float b = (float) (r + 1) / nBalls; for (int i = maxr; i >= 1; --i) { float d = (float) i / maxr; red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b); green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b); blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b); } IndexColorModel model = new IndexColorModel(8, maxr + 1, red, green, blue, 0); balls[r] = applet.createImage( new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2)); } }
Example #23
Source File: BarcodeDatamatrix.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Creates a <CODE>java.awt.Image</CODE>. A successful call to the method * <CODE>generate()</CODE> before calling this method is required. * * @param foreground the color of the bars * @param background the color of the background * @return the image */ public java.awt.Image createAwtImage(Color foreground, Color background) { if (image == null) { return null; } int f = foreground.getRGB(); int g = background.getRGB(); Canvas canvas = new Canvas(); int w = width + 2 * ws; int h = height + 2 * ws; int pix[] = new int[w * h]; int stride = (w + 7) / 8; int ptr = 0; for (int k = 0; k < h; ++k) { int p = k * stride; for (int j = 0; j < w; ++j) { int b = image[p + j / 8] & 0xff; b <<= j % 8; pix[ptr++] = (b & 0x80) == 0 ? g : f; } } java.awt.Image img = canvas.createImage(new MemoryImageSource(w, h, pix, 0, w)); return img; }
Example #24
Source File: ByteImage.java From osp with GNU General Public License v3.0 | 6 votes |
/** * Constructs IntegerImage with the given ColorModel and data. * * @param colorModel * @param data */ public ByteImage(ColorModel colorModel, byte[][] data) { nrow = data.length; ncol = data[0].length; imagePixels = new byte[nrow * ncol]; for (int i = 0; i < nrow; i++) { byte[] row = data[i]; System.arraycopy(row, 0, imagePixels, i * ncol, ncol); } imageSource = new MemoryImageSource(ncol, nrow,colorModel, imagePixels, 0, ncol); imageSource.setAnimated(true); image = Toolkit.getDefaultToolkit().createImage(imageSource); dirtyImage=false; xmin = 0; xmax = ncol; ymin = nrow; ymax = 0; // zero is on top }
Example #25
Source File: ImageTransferTest.java From hottub with GNU General Public License v2.0 | 6 votes |
private static Image createImage() { int w = 100; int h = 100; int[] pix = new int[w * h]; int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red = 127; int green = 127; int blue = y > h / 2 ? 127 : 0; int alpha = 255; if (x < w / 4 && y < h / 4) { alpha = 0; red = 0; } pix[index++] = (alpha << 24) | (red << 16) | (green << 8) | blue; } } return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pix, 0, w)); }
Example #26
Source File: XYZApp.java From hottub with GNU General Public License v2.0 | 6 votes |
private void Setup() { balls = new Image[nBalls]; byte red[] = new byte[256]; red[0] = (byte) bgGrey; byte green[] = new byte[256]; green[0] = (byte) bgGrey; byte blue[] = new byte[256]; blue[0] = (byte) bgGrey; for (int r = 0; r < nBalls; r++) { float b = (float) (r + 1) / nBalls; for (int i = maxr; i >= 1; --i) { float d = (float) i / maxr; red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b); green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b); blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b); } IndexColorModel model = new IndexColorModel(8, maxr + 1, red, green, blue, 0); balls[r] = applet.createImage( new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2)); } }
Example #27
Source File: XYZApp.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private void Setup() { balls = new Image[nBalls]; byte red[] = new byte[256]; red[0] = (byte) bgGrey; byte green[] = new byte[256]; green[0] = (byte) bgGrey; byte blue[] = new byte[256]; blue[0] = (byte) bgGrey; for (int r = 0; r < nBalls; r++) { float b = (float) (r + 1) / nBalls; for (int i = maxr; i >= 1; --i) { float d = (float) i / maxr; red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b); green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b); blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b); } IndexColorModel model = new IndexColorModel(8, maxr + 1, red, green, blue, 0); balls[r] = applet.createImage( new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2)); } }
Example #28
Source File: ImageWrapper.java From gsn with GNU General Public License v3.0 | 5 votes |
private void readObject ( ObjectInputStream stream ) throws java.io.IOException { try { stream.defaultReadObject( ); // read non-transient, non-static data Dimension dim = ( Dimension ) stream.readObject( ); Object img = stream.readObject( ); int [ ] pix = ( int [ ] ) img; Toolkit toolKit = Toolkit.getDefaultToolkit( ); image = toolKit.createImage( new MemoryImageSource( dim.width , dim.height , pix , 0 , dim.width ) ); } catch ( ClassNotFoundException e ) { throw new java.io.IOException( ); } }
Example #29
Source File: DitherTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Calculates and returns the image. Halts the calculation and returns * null if the Applet is stopped during the calculation. */ private Image calculateImage() { Thread me = Thread.currentThread(); int width = canvas.getSize().width; int height = canvas.getSize().height; int xvals[] = new int[2]; int yvals[] = new int[2]; int xmethod = XControls.getParams(xvals); int ymethod = YControls.getParams(yvals); int pixels[] = new int[width * height]; int c[] = new int[4]; //temporarily holds R,G,B,A information int index = 0; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { c[0] = c[1] = c[2] = 0; c[3] = 255; if (xmethod < ymethod) { applyMethod(c, xmethod, i, width, xvals); applyMethod(c, ymethod, j, height, yvals); } else { applyMethod(c, ymethod, j, height, yvals); applyMethod(c, xmethod, i, width, xvals); } pixels[index++] = ((c[3] << 24) | (c[0] << 16) | (c[1] << 8) | c[2]); } // Poll once per row to see if we've been told to stop. if (runner != me) { return null; } } return createImage(new MemoryImageSource(width, height, ColorModel.getRGBdefault(), pixels, 0, width)); }
Example #30
Source File: Barcode39.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** Creates a <CODE>java.awt.Image</CODE>. This image only * contains the bars without any text. * @param foreground the color of the bars * @param background the color of the background * @return the image */ public java.awt.Image createAwtImage(Color foreground, Color background) { int f = foreground.getRGB(); int g = background.getRGB(); Canvas canvas = new Canvas(); String bCode = code; if (extended) bCode = getCode39Ex(code); if (generateChecksum) bCode += getChecksum(bCode); int len = bCode.length() + 2; int nn = (int)n; int fullWidth = len * (6 + 3 * nn) + (len - 1); byte bars[] = getBarsCode39(bCode); boolean print = true; int ptr = 0; int height = (int)barHeight; int pix[] = new int[fullWidth * height]; for (int k = 0; k < bars.length; ++k) { int w = (bars[k] == 0 ? 1 : nn); int c = g; if (print) c = f; print = !print; for (int j = 0; j < w; ++j) pix[ptr++] = c; } for (int k = fullWidth; k < pix.length; k += fullWidth) { System.arraycopy(pix, 0, pix, k, fullWidth); } Image img = canvas.createImage(new MemoryImageSource(fullWidth, height, pix, 0, fullWidth)); return img; }