Example usage for java.awt.image MemoryImageSource MemoryImageSource

List of usage examples for java.awt.image MemoryImageSource MemoryImageSource

Introduction

In this page you can find the example usage for java.awt.image MemoryImageSource MemoryImageSource.

Prototype

public MemoryImageSource(int w, int h, int[] pix, int off, int scan) 

Source Link

Document

Constructs an ImageProducer object which uses an array of integers in the default RGB ColorModel to produce data for an Image object.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    int[] pixels = new int[16 * 16];
    Image image = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(16, 16, pixels, 0, 16));
    Cursor transparentCursor = Toolkit.getDefaultToolkit().createCustomCursor(image, new Point(0, 0),
            "invisibleCursor");
}

From source file:MainClass.java

public void paint(Graphics gg) {
    int h = 150;// ww  w .  j a  v a 2 s.  c  o m
    int w = 150;

    int pixels[] = new int[w * h];
    int i = 0;
    int r = 0, g = 0, b = 0;

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < h; x++) {
            r = (x ^ y) & 0xff;
            g = (x * 2 ^ y * 2) & 0xff;
            b = (x * 4 ^ y * 4) & 0xff;
            pixels[i++] = (255 << 24) | (r << 16) | (g << 8) | b;
        }
    }

    Image art = createImage(new MemoryImageSource(w, h, pixels, 0, w));

    gg.drawImage(art, 0, 0, this);
}

From source file:MemoryImageGenerator.java

public void init() {
    Dimension d = getSize();// www .  j  av  a 2 s  .c  o m
    int w = d.width;
    int h = d.height;
    int pixels[] = new int[w * h];
    int i = 0;

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int r = (x ^ y) & 0xff;
            int g = (x * 2 ^ y * 2) & 0xff;
            int b = (x * 4 ^ y * 4) & 0xff;
            pixels[i++] = (255 << 24) | (r << 16) | (g << 8) | b;
        }
    }
    img = createImage(new MemoryImageSource(w, h, pixels, 0, w));
}

From source file:MainClass.java

public void init() {
    MediaTracker mt = new MediaTracker(this);
    i = getImage(getDocumentBase(), "ora-icon.gif");
    mt.addImage(i, 0);/* w w  w  .  j  a  v  a2  s.c om*/
    try {
        mt.waitForAll();
        int width = i.getWidth(this);
        int height = i.getHeight(this);
        int pixels[] = new int[width * height];
        PixelGrabber pg = new PixelGrabber(i, 0, 0, width, height, pixels, 0, width);
        if (pg.grabPixels() && ((pg.status() & ImageObserver.ALLBITS) != 0)) {
            j = createImage(
                    new MemoryImageSource(width, height, rowFlipPixels(pixels, width, height), 0, width));
            k = createImage(
                    new MemoryImageSource(width, height, colFlipPixels(pixels, width, height), 0, width));
            l = createImage(
                    new MemoryImageSource(height, width, rot90Pixels(pixels, width, height), 0, height));
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:GrabandFade.java

public void init() {
    URL url;/* w  w  w  . j  a v a  2s.  co  m*/
    try {
        // set imageURLString here
        url = new URL(imageURLString);
        originalImage = getImage(url);
    } catch (MalformedURLException me) {
        showStatus("Malformed URL: " + me.getMessage());
    }

    /*
     * Create PixelGrabber and use it to fill originalPixelArray with image
     * pixel data. This array will then by used by the MemoryImageSource.
     */
    try {
        PixelGrabber grabber = new PixelGrabber(originalImage, 0, 0, -1, -1, true);
        if (grabber.grabPixels()) {
            width = grabber.getWidth();
            height = grabber.getHeight();
            originalPixelArray = (int[]) grabber.getPixels();

            mis = new MemoryImageSource(width, height, originalPixelArray, 0, width);
            mis.setAnimated(true);
            newImage = createImage(mis);
        } else {
            System.err.println("Grabbing Failed");
        }
    } catch (InterruptedException ie) {
        System.err.println("Pixel Grabbing Interrupted");
    }
}

From source file:GrabandFadewithRasters.java

public void init() {
    URL url;//from   w ww.j av  a  2s. com
    try {
        url = new URL(imageURLString);
        originalImage = getImage(url);
    } catch (MalformedURLException me) {
        showStatus("Malformed URL: " + me.getMessage());
    }

    try {
        PixelGrabber grabber = new PixelGrabber(originalImage, 0, 0, -1, -1, true);
        if (grabber.grabPixels()) {
            width = grabber.getWidth();
            height = grabber.getHeight();
            originalPixelArray = (int[]) grabber.getPixels();

            mis = new MemoryImageSource(width, height, originalPixelArray, 0, width);
            mis.setAnimated(true);
            newImage = createImage(mis);
        } else {
            System.err.println("Grabbing Failed");
        }
    } catch (InterruptedException ie) {
        System.err.println("Pixel Grabbing Interrupted");
    }

    DataBufferInt dbi = new DataBufferInt(originalPixelArray, width * height);

    int bandmasks[] = { 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff };
    SampleModel sm;
    sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, width, height, bandmasks);

    raster = Raster.createWritableRaster(sm, dbi, null);
}

From source file:ImageFrame.java

/**
 * Set the image from a 1D RGB pixel array.
 *///from   w  w  w .jav  a  2  s .  c  o  m
public void setImage(int w, int h, int pix[]) {
    setImage(createImage(new MemoryImageSource(w, h, pix, 0, w)));
}

From source file:MemImage.java

/** Construct a MemImage with a specified width and height */
public MemImage(int w, int h) {
    this.w = w;/*w  w w.  j  a v a 2s  .  c  om*/
    this.h = h;
    int pix[] = new int[w * h];
    int index = 0;
    for (int y = 0; y < h; y++) {
        int red = (y * 255) / (h - 1);
        for (int x = 0; x < w; x++) {
            int blue = (x * 255) / (w - 1);
            pix[index++] = (255 << 24) | (red << 16) | blue;
        }
    }
    img = createImage(new MemoryImageSource(w, h, pix, 0, w));
    setSize(getPreferredSize());
}

From source file:com.wet.wired.jsr.player.ScreenPlayer.java

private void clearImage() {
    if (area != null) {
        mis = new MemoryImageSource(area.width, area.height, new int[frameSize], 0, area.width);
        mis.setAnimated(true);//from   w w w .j  a  v a  2  s .  c o m
        listener.showNewImage(Toolkit.getDefaultToolkit().createImage(mis));
    }
}

From source file:com.wet.wired.jsr.player.ScreenPlayer.java

private void readFrame() throws IOException {

    FrameDecompressor.FramePacket frame = decompressor.unpack();

    int result = frame.getResult();
    if (result == 0) {
        // empty image, because no change
        frameNr++;// w ww.ja  v a 2  s .c  o  m
        frameSize = frame.getData().length;
        frameTime = frame.getTimeStamp();
        return;
    } else if (result == -1) {
        // end of file, stop
        running = false;
        return;
    }

    frameNr++;
    frameSize = frame.getData().length;
    frameTime = frame.getTimeStamp();

    if (mis == null) {
        mis = new MemoryImageSource(area.width, area.height, frame.getData(), 0, area.width);
        mis.setAnimated(true);
        listener.showNewImage(Toolkit.getDefaultToolkit().createImage(mis));
        return;
    } else {
        mis.newPixels(frame.getData(), ColorModel.getRGBdefault(), 0, area.width);
        return;
    }

}