Java Code Examples for java.awt.Canvas#createImage()
The following examples show how to use
java.awt.Canvas#createImage() .
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 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 2
Source File: Barcode128.java From gcs with Mozilla Public License 2.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; if (codeType == CODE128_RAW) { int idx = code.indexOf('\uffff'); if (idx >= 0) bCode = code.substring(0, idx); else bCode = code; } else { bCode = getRawText(code, codeType == CODE128_UCC); } int len = bCode.length(); int fullWidth = (len + 2) * 11 + 2; byte bars[] = getBarsCode128Raw(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]; 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; }
Example 3
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; }
Example 4
Source File: BarcodeInter25.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 = keepNumbers(code); if (generateChecksum) bCode += getChecksum(bCode); int len = bCode.length(); int nn = (int)n; int fullWidth = len * (3 + 2 * nn) + (6 + nn ); byte bars[] = getBarsInter25(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; }
Example 5
Source File: BarcodePDF417.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** Creates a <CODE>java.awt.Image</CODE>. * @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(); paintCode(); int h = (int)yHeight; int pix[] = new int[bitColumns * codeRows * h]; int stride = (bitColumns + 7) / 8; int ptr = 0; for (int k = 0; k < codeRows; ++k) { int p = k * stride; for (int j = 0; j < bitColumns; ++j) { int b = outBits[p + (j / 8)] & 0xff; b <<= j % 8; pix[ptr++] = (b & 0x80) == 0 ? g : f; } for (int j = 1; j < h; ++j) { System.arraycopy(pix, ptr - bitColumns, pix, ptr + bitColumns * (j - 1), bitColumns); } ptr += bitColumns * (h - 1); } java.awt.Image img = canvas.createImage(new MemoryImageSource(bitColumns, codeRows * h, pix, 0, bitColumns)); return img; }
Example 6
Source File: BarcodeCodabar.java From gcs with Mozilla Public License 2.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 fullCode = code; if (generateChecksum && checksumText) fullCode = calculateChecksum(code); if (!startStopText) fullCode = fullCode.substring(1, fullCode.length() - 1); byte bars[] = getBarsCodabar(generateChecksum ? calculateChecksum(code) : code); int wide = 0; for (int k = 0; k < bars.length; ++k) { wide += bars[k]; } int narrow = bars.length - wide; int fullWidth = narrow + wide * (int)n; 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 : (int)n); 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; }
Example 7
Source File: BarcodeInter25.java From gcs with Mozilla Public License 2.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 = keepNumbers(code); if (generateChecksum) bCode += getChecksum(bCode); int len = bCode.length(); int nn = (int)n; int fullWidth = len * (3 + 2 * nn) + (6 + nn ); byte bars[] = getBarsInter25(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; }
Example 8
Source File: BarcodePDF417.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Creates a <CODE>java.awt.Image</CODE>. * * @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(); paintCode(); int h = (int) yHeight; int pix[] = new int[bitColumns * codeRows * h]; int stride = (bitColumns + 7) / 8; int ptr = 0; for (int k = 0; k < codeRows; ++k) { int p = k * stride; for (int j = 0; j < bitColumns; ++j) { int b = outBits[p + j / 8] & 0xff; b <<= j % 8; pix[ptr++] = (b & 0x80) == 0 ? g : f; } for (int j = 1; j < h; ++j) { System.arraycopy(pix, ptr - bitColumns, pix, ptr + bitColumns * (j - 1), bitColumns); } ptr += bitColumns * (h - 1); } java.awt.Image img = canvas.createImage(new MemoryImageSource(bitColumns, codeRows * h, pix, 0, bitColumns)); return img; }
Example 9
Source File: BarcodePostnet.java From gcs with Mozilla Public License 2.0 | 4 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(); int barWidth = (int)x; if (barWidth <= 0) barWidth = 1; int barDistance = (int)n; if (barDistance <= barWidth) barDistance = barWidth + 1; int barShort = (int)size; if (barShort <= 0) barShort = 1; int barTall = (int)barHeight; if (barTall <= barShort) barTall = barShort + 1; int width = ((code.length() + 1) * 5 + 1) * barDistance + barWidth; int pix[] = new int[width * barTall]; byte bars[] = getBarsPostnet(code); byte flip = 1; if (codeType == PLANET) { flip = 0; bars[0] = 0; bars[bars.length - 1] = 0; } int idx = 0; for (int k = 0; k < bars.length; ++k) { boolean dot = (bars[k] == flip); for (int j = 0; j < barDistance; ++j) { pix[idx + j] = ((dot && j < barWidth) ? f : g); } idx += barDistance; } int limit = width * (barTall - barShort); for (int k = width; k < limit; k += width) System.arraycopy(pix, 0, pix, k, width); idx = limit; for (int k = 0; k < bars.length; ++k) { for (int j = 0; j < barDistance; ++j) { pix[idx + j] = ((j < barWidth) ? f : g); } idx += barDistance; } for (int k = limit + width; k < pix.length; k += width) System.arraycopy(pix, limit, pix, k, width); Image img = canvas.createImage(new MemoryImageSource(width, barTall, pix, 0, width)); return img; }
Example 10
Source File: ImageTests.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public Image makeImage(TestEnvironment env, int w, int h) { Canvas c = env.getCanvas(); return c.createImage(w, h); }
Example 11
Source File: ImageTests.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public Image makeImage(TestEnvironment env, int w, int h) { Canvas c = env.getCanvas(); return c.createImage(w, h); }
Example 12
Source File: ImageTests.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public Image makeImage(TestEnvironment env, int w, int h) { Canvas c = env.getCanvas(); return c.createImage(w, h); }
Example 13
Source File: ImageTests.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public Image makeImage(TestEnvironment env, int w, int h) { Canvas c = env.getCanvas(); return c.createImage(w, h); }
Example 14
Source File: BarcodeEAN.java From gcs with Mozilla Public License 2.0 | 4 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(); int width = 0; byte bars[] = null; switch (codeType) { case EAN13: bars = getBarsEAN13(code); width = 11 + 12 * 7; break; case EAN8: bars = getBarsEAN8(code); width = 11 + 8 * 7; break; case UPCA: bars = getBarsEAN13("0" + code); width = 11 + 12 * 7; break; case UPCE: bars = getBarsUPCE(code); width = 9 + 6 * 7; break; case SUPP2: bars = getBarsSupplemental2(code); width = 6 + 2 * 7; break; case SUPP5: bars = getBarsSupplemental5(code); width = 4 + 5 * 7 + 4 * 2; break; default: throw new RuntimeException("Invalid code type."); } boolean print = true; int ptr = 0; int height = (int)barHeight; int pix[] = new int[width * height]; for (int k = 0; k < bars.length; ++k) { int w = bars[k]; int c = g; if (print) c = f; print = !print; for (int j = 0; j < w; ++j) pix[ptr++] = c; } for (int k = width; k < pix.length; k += width) { System.arraycopy(pix, 0, pix, k, width); } Image img = canvas.createImage(new MemoryImageSource(width, height, pix, 0, width)); return img; }
Example 15
Source File: ImageTests.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public Image makeImage(TestEnvironment env, int w, int h) { Canvas c = env.getCanvas(); return c.createImage(w, h); }
Example 16
Source File: ImageTests.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public Image makeImage(TestEnvironment env, int w, int h) { Canvas c = env.getCanvas(); return c.createImage(w, h); }
Example 17
Source File: ImageTests.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public Image makeImage(TestEnvironment env, int w, int h) { Canvas c = env.getCanvas(); return c.createImage(w, h); }
Example 18
Source File: BarcodeEAN.java From itext2 with GNU Lesser General Public License v3.0 | 4 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(); int width = 0; byte bars[] = null; switch (codeType) { case EAN13: bars = getBarsEAN13(code); width = 11 + 12 * 7; break; case EAN8: bars = getBarsEAN8(code); width = 11 + 8 * 7; break; case UPCA: bars = getBarsEAN13("0" + code); width = 11 + 12 * 7; break; case UPCE: bars = getBarsUPCE(code); width = 9 + 6 * 7; break; case SUPP2: bars = getBarsSupplemental2(code); width = 6 + 2 * 7; break; case SUPP5: bars = getBarsSupplemental5(code); width = 4 + 5 * 7 + 4 * 2; break; default: throw new RuntimeException("Invalid code type."); } boolean print = true; int ptr = 0; int height = (int)barHeight; int pix[] = new int[width * height]; for (int k = 0; k < bars.length; ++k) { int w = bars[k]; int c = g; if (print) c = f; print = !print; for (int j = 0; j < w; ++j) pix[ptr++] = c; } for (int k = width; k < pix.length; k += width) { System.arraycopy(pix, 0, pix, k, width); } Image img = canvas.createImage(new MemoryImageSource(width, height, pix, 0, width)); return img; }
Example 19
Source File: ImageTests.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public Image makeImage(TestEnvironment env, int w, int h) { Canvas c = env.getCanvas(); return c.createImage(w, h); }
Example 20
Source File: ImageTests.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public Image makeImage(TestEnvironment env, int w, int h) { Canvas c = env.getCanvas(); return c.createImage(w, h); }