Java Code Examples for java.awt.image.MemoryImageSource

The following examples show how to use java.awt.image.MemoryImageSource. These examples are extracted from open source projects.
Example 1
Project: dragonwell8_jdk   File: XYZApp.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 2
Project: dragonwell8_jdk   File: ImageTransferTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 3
Project: TencentKona-8   File: XYZApp.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 4
Project: TencentKona-8   File: ImageTransferTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 5
Project: jdk8u60   File: XYZApp.java    License: GNU General Public License v2.0 6 votes vote down vote up
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
Project: openjdk-jdk8u   File: XYZApp.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 7
Project: openjdk-jdk8u   File: ImageTransferTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 8
Project: openjdk-jdk8u-backup   File: XYZApp.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 9
Project: openjdk-jdk8u-backup   File: ImageTransferTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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
Project: openjdk-jdk9   File: XYZApp.java    License: GNU General Public License v2.0 6 votes vote down vote up
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
Project: openjdk-jdk9   File: ImageTransferTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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
Project: jdk8u-jdk   File: XYZApp.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 13
Project: jdk8u-jdk   File: ImageTransferTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 14
Project: gcs   File: BarcodeDatamatrix.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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 15
Project: itext2   File: BarcodeDatamatrix.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 16
Project: hottub   File: XYZApp.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 17
Project: hottub   File: ImageTransferTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 18
Project: osp   File: ByteImage.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 19
Project: openjdk-8-source   File: XYZApp.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 20
Project: openjdk-8   File: XYZApp.java    License: GNU General Public License v2.0 6 votes vote down vote up
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
Project: jdk8u_jdk   File: XYZApp.java    License: GNU General Public License v2.0 6 votes vote down vote up
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
Project: jdk8u_jdk   File: ImageTransferTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 23
Project: mars-sim   File: StarRater.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 24
Project: jdk8u-jdk   File: XYZApp.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 25
Project: RipplePower   File: GraphicsUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 将黑色颜色部分透明化
 * 
 * @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 26
Project: RipplePower   File: GraphicsUtils.java    License: Apache License 2.0 6 votes vote down vote up
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 27
Project: libreveris   File: TestImage.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
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 28
Project: dragonwell8_jdk   File: DitherTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 29
Project: TencentKona-8   File: DitherTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
Project: jdk8u60   File: DitherTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 31
Project: openjdk-jdk8u   File: DitherTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 32
Project: openjdk-jdk8u-backup   File: DitherTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 33
Project: openjdk-jdk9   File: DitherTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 34
Project: jdk8u-jdk   File: DitherTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 35
Project: gcs   File: BarcodePDF417.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 36
Project: gcs   File: BarcodeInter25.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/** 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 37
Project: gcs   File: Barcode128.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/** 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 38
Project: gcs   File: Barcode39.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/** 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 39
Project: gcs   File: BarcodeCodabar.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/** 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 40
Project: JewelCrawler   File: ImageFilter.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** 图像二值化 */
public BufferedImage changeGrey() {
	PixelGrabber pg = new PixelGrabber(image.getSource(), 0, 0, iw, ih, pixels, 0, iw);
	try {
		pg.grabPixels();
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	// 设定二值化的域值,默认值为100
	int grey = 100;
	// 对图像进行二值化处理,Alpha值保持不变
	ColorModel cm = ColorModel.getRGBdefault();
	for (int i = 0; i < iw * ih; i++) {
		int red, green, blue;
		int alpha = cm.getAlpha(pixels[i]);
		if (cm.getRed(pixels[i]) > grey) {
			red = 255;
		} else {
			red = 0;
		}

		if (cm.getGreen(pixels[i]) > grey) {
			green = 255;
		} else {
			green = 0;
		}

		if (cm.getBlue(pixels[i]) > grey) {
			blue = 255;
		} else {
			blue = 0;
		}

		pixels[i] = alpha << 24 | red << 16 | green << 8 | blue;
	}
	// 将数组中的象素产生一个图像
	return ImageIOHelper.imageProducerToBufferedImage(new MemoryImageSource(iw, ih, pixels, 0, iw));
}