Example usage for java.awt.image ColorModel getRGBdefault

List of usage examples for java.awt.image ColorModel getRGBdefault

Introduction

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

Prototype

public static ColorModel getRGBdefault() 

Source Link

Document

Returns a DirectColorModel that describes the default format for integer RGB values used in many of the methods in the AWT image interfaces for the convenience of the programmer.

Usage

From source file:Main.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true);

    gp1.createContext(ColorModel.getRGBdefault(), new Rectangle(0, 0, 30, 40), new Rectangle(0, 0, 30, 40),
            new AffineTransform(), null);

    System.out.println(gp1.getTransparency());
    g2d.setPaint(gp1);//w  w  w.j  a v a 2s  .  c  om
    g2d.fillRect(20, 20, 300, 40);

}

From source file:Main.java

public void paint(Graphics g) {
    BufferedImage bim;//from  ww  w . j  a  va2 s  . co  m

    TexturePaint tp;

    String mesg = "www.java2s.com";

    Font myFont = new Font("Lucida Regular", Font.BOLD, 72);

    Color[] colors = { Color.red, Color.blue, Color.yellow, };

    int width = 8, height = 8;
    bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bim.createGraphics();
    for (int i = 0; i < width; i++) {
        g2.setPaint(colors[(i / 2) % colors.length]);
        g2.drawLine(0, i, i, 0);
        g2.drawLine(width - i, height, width, height - i);
    }
    Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight());
    tp = new TexturePaint(bim, r);
    tp.createContext(ColorModel.getRGBdefault(), new Rectangle(10, 10, 20, 20), null, null, null);

    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setPaint(tp);
    g2d.setFont(myFont);
    g2d.drawString(mesg, 20, 100);
}

From source file:MainClass.java

public void imageComplete(int status) {
    if ((status == IMAGEERROR) || (status == IMAGEABORTED)) {
        consumer.imageComplete(status);//from   w w w  .  j  a  v a2 s  . co m
        return;
    } else {
        int xWidth = imageWidth / iterations;
        if (xWidth <= 0)
            xWidth = 1;
        int newPixels[] = new int[xWidth * imageHeight];
        int iColor = overlapColor.getRGB();
        for (int x = 0; x < (xWidth * imageHeight); x++)
            newPixels[x] = iColor;
        int t = 0;
        for (; t < (imageWidth - xWidth); t += xWidth) {
            consumer.setPixels(t, 0, xWidth, imageHeight, ColorModel.getRGBdefault(), newPixels, 0, xWidth);
            consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
            try {
                Thread.sleep(delay);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        int left = imageWidth - t;
        if (left > 0) {
            consumer.setPixels(imageWidth - left, 0, left, imageHeight, ColorModel.getRGBdefault(), newPixels,
                    0, xWidth);
            consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
        }
        consumer.imageComplete(STATICIMAGEDONE);
    }
}

From source file:BMPLoader.java

public MemoryImageSource getImageSource() {
    ColorModel cm;//from   w  w  w  . ja  v a  2 s  . c  om
    MemoryImageSource mis;
    if (noOfEntries > 0) {
        // There is a color palette; create an IndexColorModel
        cm = new IndexColorModel(bitsPerPixel, noOfEntries, r, g, b);
    } else {
        // There is no palette; use the default RGB color model
        cm = ColorModel.getRGBdefault();
    }
    // Create MemoryImageSource
    if (bitsPerPixel > 8) {
        // use one int per pixel
        mis = new MemoryImageSource(width, height, cm, intData, 0, width);
    } else {
        // use one byte per pixel
        mis = new MemoryImageSource(width, height, cm, byteData, 0, width);
    }
    return mis; // this can be used by JComponent.createImage()
}

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 .  j  av 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;
    }

}

From source file:org.gallery.web.controller.ImageController.java

public static boolean compressImg(BufferedImage src, File outfile, double d) {
    FileOutputStream out = null;//from   w  w  w. j  a  v  a  2  s  . c o  m
    ImageWriter imgWrier;
    ImageWriteParam imgWriteParams;

    // ? jpg
    imgWrier = ImageIO.getImageWritersByFormatName("jpg").next();
    imgWriteParams = new javax.imageio.plugins.jpeg.JPEGImageWriteParam(null);
    // ??MODE_EXPLICIT
    imgWriteParams.setCompressionMode(imgWriteParams.MODE_EXPLICIT);
    // ?qality?0~1
    imgWriteParams.setCompressionQuality((float) d);
    imgWriteParams.setProgressiveMode(imgWriteParams.MODE_DISABLED);
    ColorModel colorModel = ColorModel.getRGBdefault();
    // ?
    imgWriteParams.setDestinationType(
            new javax.imageio.ImageTypeSpecifier(colorModel, colorModel.createCompatibleSampleModel(16, 16)));

    try {
        out = new FileOutputStream(outfile);
        imgWrier.reset();
        //  out?write, ImageOutputStream?
        // OutputStream
        imgWrier.setOutput(ImageIO.createImageOutputStream(out));
        // write???
        imgWrier.write(null, new IIOImage(src, null, null), imgWriteParams);
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}