Example usage for java.awt Color getRGB

List of usage examples for java.awt Color getRGB

Introduction

In this page you can find the example usage for java.awt Color getRGB.

Prototype

public int getRGB() 

Source Link

Document

Returns the RGB value representing the color in the default sRGB ColorModel .

Usage

From source file:haven.Utils.java

public static BufferedImage outline(BufferedImage img, Color col) {
    Coord sz = imgsz(img).add(2, 2);//from  ww w . j  a  v  a2s . c om
    BufferedImage ol = TexI.mkbuf(sz);
    Object fcol = ol.getColorModel().getDataElements(col.getRGB(), null);
    Raster src = img.getRaster();
    WritableRaster dst = ol.getRaster();
    for (int y = 0; y < sz.y; y++) {
        for (int x = 0; x < sz.x; x++) {
            boolean t;
            if ((y == 0) || (x == 0) || (y == sz.y - 1) || (x == sz.x - 1)) {
                t = true;
            } else {
                t = src.getSample(x - 1, y - 1, 3) < 250;
            }
            if (!t)
                continue;
            if (((x > 1) && (y > 0) && (y < sz.y - 1) && (src.getSample(x - 2, y - 1, 3) >= 250))
                    || ((x > 0) && (y > 1) && (x < sz.x - 1) && (src.getSample(x - 1, y - 2, 3) >= 250))
                    || ((x < sz.x - 2) && (y > 0) && (y < sz.y - 1) && (src.getSample(x, y - 1, 3) >= 250))
                    || ((x > 0) && (y < sz.y - 2) && (x < sz.x - 1) && (src.getSample(x - 1, y, 3) >= 250)))
                dst.setDataElements(x, y, fcol);
        }
    }
    return (ol);
}

From source file:io.gameover.utilities.pixeleditor.Frame.java

public BufferedImage getAsBufferedImage(Color transparent) {
    BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
    for (int i = 0; i < bi.getWidth(); i++) {
        for (int j = 0; j < bi.getHeight(); j++) {
            if (transparent != null && argb[i][j] == NO_COLOR_AS_INT) {
                bi.setRGB(i, j, transparent.getRGB());
            } else {
                bi.setRGB(i, j, argb[i][j]);
            }/*from   w w  w .ja  v a  2s .  c  om*/
        }
    }
    return bi;
}

From source file:edu.umn.cs.spatialHadoop.osm.OSMEdge.java

@Override
public void draw(Graphics g, double xscale, double yscale) {
    int x1 = (int) Math.round(this.lon1 * xscale);
    int y1 = (int) Math.round(this.lat1 * yscale);
    int x2 = (int) Math.round(this.lon2 * xscale);
    int y2 = (int) Math.round(this.lat2 * yscale);
    Color shape_color = g.getColor();
    // Compute alpha to use based on edge length and image scale
    double geom_alpha = this.getLength() * (xscale + yscale) / 2.0;
    int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255);
    if (color_alpha == 0)
        return;//from   www  .  jav a2s .  com

    g.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true));
    g.drawLine(x1, y1, x2, y2);
}

From source file:edu.umn.cs.spatialHadoop.nasa.HDFRasterLayer.java

public BufferedImage asImage() {
    // Calculate the average
    float[][] avg = new float[getWidth()][getHeight()];
    for (int x = 0; x < this.getWidth(); x++) {
        for (int y = 0; y < this.getHeight(); y++) {
            avg[x][y] = (float) sum[x][y] / count[x][y];
        }//  w  w w.  ja  v  a2  s  .  c  o m
    }
    if (min >= max) {
        // Values not set. Autodetect
        min = Float.MAX_VALUE;
        max = -Float.MAX_VALUE;
        for (int x = 0; x < this.getWidth(); x++) {
            for (int y = 0; y < this.getHeight(); y++) {
                if (avg[x][y] < min)
                    min = avg[x][y];
                if (avg[x][y] > max)
                    max = avg[x][y];
            }
        }
    }
    BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
    for (int x = 0; x < this.getWidth(); x++) {
        for (int y = 0; y < this.getHeight(); y++) {
            if (count[x][y] > 0) {
                Color color = calculateColor(avg[x][y], min, max);
                image.setRGB(x, y, color.getRGB());
            } else {
                image.setRGB(x, y, 0);
            }
        }
    }
    return image;
}

From source file:edu.csun.ecs.cs.multitouchj.ui.control.Control.java

public void setColor(Color color) {
    this.color = new Color(color.getRGB());
}

From source file:com.tulskiy.musique.system.configuration.Configuration.java

public void setColor(String key, Color value) {
    if (value == null)
        remove(key);/*w w w  .  ja  va2s .c om*/
    else {
        String s = new Formatter().format("#%06X", value.getRGB() & 0xFFFFFF).toString();
        put(key, s);
    }
}

From source file:org.csml.tommo.sugar.heatmap.MeanQualityMatrix.java

public BufferedImage createBufferedImage(ColorPaintScale scale) {

    BufferedImage bi = new BufferedImage(N, N, BufferedImage.TYPE_INT_RGB);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            Color c = scale.getPaint(getMeanValues()[i][j]);
            bi.setRGB(i, N - 1 - j, c.getRGB());
        }/*  www.j av a  2s.  c  o  m*/
    }

    return bi;
}

From source file:org.csml.tommo.sugar.heatmap.MeanQualityMatrix.java

public BufferedImage createDensityBufferedImage(ColorPaintScale paintScale) {
    BufferedImage bi = new BufferedImage(N, N, BufferedImage.TYPE_INT_RGB);

    // make sure that the counter is initialized 
    getMeanValues();//from w ww. j  a  v  a 2 s .c  o m

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            Color c = paintScale.getPaint(totalValueCounter[i][j]);
            bi.setRGB(i, N - 1 - j, c.getRGB());
        }
    }

    return bi;
}

From source file:org.csml.tommo.sugar.heatmap.MeanQualityMatrix.java

public BufferedImage createAverageQualityBufferedImage(ColorPaintScale paintScale) {
    BufferedImage bi = new BufferedImage(N, N, BufferedImage.TYPE_INT_RGB);

    // make sure that the counter is initialized 
    getAverageQualityMatrix();//from  w ww .  java2 s.c  om

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            Color c = paintScale.getPaint(getAverageQualityMatrix()[i][j]);
            bi.setRGB(i, N - 1 - j, c.getRGB());
        }
    }

    return bi;
}

From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java

public static BufferedImage autoPanImage(BufferedImage img, Color bgcolor) {
    BufferedImage out = null;/*from   ww w . ja  va2  s . c o m*/
    if (img == null) {
        return null;
    }

    int bgcolorInt = bgcolor.getRGB();
    int w = img.getWidth();
    int h = img.getHeight();
    int up = 0;
    int down = h - 1;
    int left = 0;
    int right = w - 1;
    int tmp;

    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h / 2; y++) {
            tmp = img.getRGB(x, y);
            if (tmp == bgcolorInt) {
                if (y > up) {
                    up = y;
                }
            } else {
                break;
            }
        }

        for (int y = h - 1; y > h / 2; y--) {
            tmp = img.getRGB(x, y);
            if (tmp == bgcolorInt) {
                if (y < down) {
                    down = y;
                }
            } else {
                break;
            }
        }

    }

    for (int y = up; y < down; y++) {
        for (int x = 0; x < w / 2; x++) {
            tmp = img.getRGB(x, y);
            if (tmp == bgcolorInt) {
                if (x > left) {
                    left = x;
                }
            } else {
                break;
            }
        }

        for (int x = w - 1; x > w / 2; x--) {
            tmp = img.getRGB(x, y);
            if (tmp == bgcolorInt) {
                if (x < right) {
                    right = x;
                }
            } else {
                break;
            }
        }

    }

    System.out.println("up=" + up);
    System.out.println("down=" + down);
    System.out.println("left=" + left);
    System.out.println("right=" + right);

    out = img.getSubimage(left, up, right - left + 1, down - up + 1);
    return out;
}