Example usage for java.awt Transparency TRANSLUCENT

List of usage examples for java.awt Transparency TRANSLUCENT

Introduction

In this page you can find the example usage for java.awt Transparency TRANSLUCENT.

Prototype

int TRANSLUCENT

To view the source code for java.awt Transparency TRANSLUCENT.

Click Source Link

Document

Represents image data that contains or might contain arbitrary alpha values between and including 0.0 and 1.0.

Usage

From source file:de.romankreisel.faktotum.beans.BundesbruderBean.java

public void rotateProfilePictureClockwise(BundesbruderEntity bundesbruder, double angle) throws IOException {
    BufferedImage image = this.getImageFromByteArray(bundesbruder.getPictureOriginal());
    double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
    int w = image.getWidth(), h = image.getHeight();
    int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin);
    GraphicsConfiguration gc = image.createGraphics().getDeviceConfiguration();
    BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT);
    Graphics2D g = result.createGraphics();
    g.translate((neww - w) / 2, (newh - h) / 2);
    g.rotate(angle, w / 2, h / 2);//from  www .java 2  s . c  o m
    g.drawRenderedImage(image, null);
    g.dispose();
    this.setProfilePicture(bundesbruder, this.storeImageToByteArray(image));
}

From source file:com.t3.image.ImageUtil.java

/**
 * Look at the image and determine which Transparency is most appropriate.
 * If it finds any translucent pixels it returns Transparency.TRANSLUCENT, if 
 * it finds at least one purely transparent pixel and no translucent pixels
 * it will return Transparency.BITMASK, in all other cases it returns 
 * Transparency.OPAQUE, including errors
 * //  w  w w.  j a v  a2s.  c  o  m
 * @param image
 * @return one of Transparency constants
 */
public static int pickBestTransparency(Image image) {

    // Take a shortcut if possible
    if (image instanceof BufferedImage) {
        return pickBestTransparency((BufferedImage) image);
    }

    // Legacy method
    // NOTE: This is a horrible memory hog
    int width = image.getWidth(null);
    int height = image.getHeight(null);
    int[] pixelArray = new int[width * height];
    PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, pixelArray, 0, width);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        System.err.println("interrupted waiting for pixels!");
        return Transparency.OPAQUE;
    }

    if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
        System.err.println("image fetch aborted or errored");
        return Transparency.OPAQUE;
    }

    // Look for specific pixels
    boolean foundTransparent = false;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            // Get the next pixel
            int pixel = pixelArray[y * width + x];
            int alpha = (pixel >> 24) & 0xff;

            // Is there translucency or just pure transparency ?
            if (alpha > 0 && alpha < 255) {
                return Transparency.TRANSLUCENT;
            }

            if (alpha == 0 && !foundTransparent) {
                foundTransparent = true;
            }
        }
    }

    return foundTransparent ? Transparency.BITMASK : Transparency.OPAQUE;
}

From source file:net.rptools.lib.image.ImageUtil.java

/**
 * Look at the image and determine which Transparency is most appropriate. If it finds any translucent pixels it
 * returns Transparency.TRANSLUCENT, if it finds at least one purely transparent pixel and no translucent pixels it
 * will return Transparency.BITMASK, in all other cases it returns Transparency.OPAQUE, including errors
 * /*from ww  w  .  j a  v  a  2s.  com*/
 * @param image
 * @return one of Transparency constants
 */
public static int pickBestTransparency(Image image) {
    // Take a shortcut if possible
    if (image instanceof BufferedImage) {
        return pickBestTransparency((BufferedImage) image);
    }

    // Legacy method
    // NOTE: This is a horrible memory hog
    int width = image.getWidth(null);
    int height = image.getHeight(null);
    int[] pixelArray = new int[width * height];
    PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, pixelArray, 0, width);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        System.err.println("interrupted waiting for pixels!");
        return Transparency.OPAQUE;
    }
    if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
        System.err.println("image fetch aborted or errored");
        return Transparency.OPAQUE;
    }
    // Look for specific pixels
    boolean foundTransparent = false;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            // Get the next pixel
            int pixel = pixelArray[y * width + x];
            int alpha = (pixel >> 24) & 0xff;

            // Is there translucency or just pure transparency ?
            if (alpha > 0 && alpha < 255) {
                return Transparency.TRANSLUCENT;
            }
            if (alpha == 0 && !foundTransparent) {
                foundTransparent = true;
            }
        }
    }
    return foundTransparent ? Transparency.BITMASK : Transparency.OPAQUE;
}

From source file:org.apache.xmlgraphics.image.loader.impl.PNGFile.java

public ImageRawPNG getImageRawPNG(final ImageInfo info) throws ImageException, IOException {
    try (final InputStream seqStream = new SequenceInputStream(Collections.enumeration(this.streamVec))) {
        switch (this.colorType) {
        case PNG_COLOR_GRAY:
            if (this.hasPalette) {
                throw new ImageException("Corrupt PNG: color palette is not allowed!");
            }/*from   w w w  .  j  a  v a2s  . c o m*/
            this.colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false,
                    Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
            break;
        case PNG_COLOR_RGB:
            // actually a check of the sRGB chunk would be necessary to
            // confirm
            // if it's really sRGB
            this.colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
                    Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
            break;
        case PNG_COLOR_PALETTE:
            if (this.hasAlphaPalette) {
                this.colorModel = new IndexColorModel(this.bitDepth, this.paletteEntries, this.redPalette,
                        this.greenPalette, this.bluePalette, this.alphaPalette);
            } else {
                this.colorModel = new IndexColorModel(this.bitDepth, this.paletteEntries, this.redPalette,
                        this.greenPalette, this.bluePalette);
            }
            break;
        case PNG_COLOR_GRAY_ALPHA:
            if (this.hasPalette) {
                throw new ImageException("Corrupt PNG: color palette is not allowed!");
            }
            this.colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), true, false,
                    Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
            break;
        case PNG_COLOR_RGB_ALPHA:
            // actually a check of the sRGB chunk would be necessary to
            // confirm
            // if it's really sRGB
            this.colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), true, false,
                    Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
            break;
        default:
            throw new ImageException("Unsupported color type: " + this.colorType);
        }
        // the iccProfile is still null for now
        final ImageRawPNG rawImage = new ImageRawPNG(info, seqStream, this.colorModel, this.bitDepth,
                this.iccProfile);
        if (this.isTransparent) {
            if (this.colorType == PNG_COLOR_GRAY) {
                rawImage.setGrayTransparentAlpha(this.grayTransparentAlpha);
            } else if (this.colorType == PNG_COLOR_RGB) {
                rawImage.setRGBTransparentAlpha(this.redTransparentAlpha, this.greenTransparentAlpha,
                        this.blueTransparentAlpha);
            } else if (this.colorType == PNG_COLOR_PALETTE) {
                rawImage.setTransparent();
            } else {
                //
            }
        }
        return rawImage;
    }
}

From source file:com.t3.image.ImageUtil.java

public static int pickBestTransparency(BufferedImage image) {

    // See if we can short circuit
    ColorModel colorModel = image.getColorModel();
    if (colorModel.getTransparency() == Transparency.OPAQUE) {
        return Transparency.OPAQUE;
    }// w ww  .  j a  va  2  s  .c  o m

    // Get the pixels
    int width = image.getWidth();
    int height = image.getHeight();

    // Look for specific pixels
    boolean foundTransparent = false;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            // Get the next pixel
            int pixel = image.getRGB(x, y);
            int alpha = (pixel >> 24) & 0xff;

            // Is there translucency or just pure transparency ?
            if (alpha > 0 && alpha < 255) {
                return Transparency.TRANSLUCENT;
            }

            if (alpha == 0 && !foundTransparent) {
                foundTransparent = true;
            }
        }
    }

    return foundTransparent ? Transparency.BITMASK : Transparency.OPAQUE;
}

From source file:net.rptools.lib.image.ImageUtil.java

public static int pickBestTransparency(BufferedImage image) {
    // See if we can short circuit
    ColorModel colorModel = image.getColorModel();
    if (colorModel.getTransparency() == Transparency.OPAQUE) {
        return Transparency.OPAQUE;
    }//from   www  .  j a  v  a  2 s .co  m
    // Get the pixels
    int width = image.getWidth();
    int height = image.getHeight();

    // Look for specific pixels
    boolean foundTransparent = false;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            // Get the next pixel
            int pixel = image.getRGB(x, y);
            int alpha = (pixel >> 24) & 0xff;

            // Is there translucency or just pure transparency ?
            if (alpha > 0 && alpha < 255) {
                return Transparency.TRANSLUCENT;
            }
            if (alpha == 0 && !foundTransparent) {
                foundTransparent = true;
            }
        }
    }
    return foundTransparent ? Transparency.BITMASK : Transparency.OPAQUE;
}

From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java

private void updateLegend() {

    int width = DEFAULT_LEGEND_WIDTH;
    int height = DEFAULT_LEGENT_HEIGHT;
    legend = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getDefaultConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);
    Graphics2D g = (Graphics2D) legend.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.setPaint(UI.colorBlack2);//from w w  w  . ja v a2  s. c  o  m
    g.fillRoundRect(0, 0, width, height - 12, 5, 5);

    g.setColor(barColorBelow);
    int boxNum = 10;
    g.setStroke(UI.stroke1_5);

    double value;
    for (int i = 0; i < boxNum; i++) {
        value = _minValue + (_maxValue - _minValue) / boxNum * i;

        if (value > disectBound) {
            g.setColor(barColorNormal);
        }

        int h = (height - 12) / boxNum * i;
        g.drawLine(i * width / boxNum, height - 12 - h, (i + 1) * width / boxNum, height - 12 - h);

    }

    g.setColor(Color.BLACK);
    g.setFont(UI.fontMono.deriveFont(10f));
    DecimalFormat format = new DecimalFormat("#.##");
    g.drawString(format.format(_minValue), 2, 23);

    g.setColor(Color.BLACK);
    String maxString = format.format(_maxValue);
    int swidth = g.getFontMetrics().stringWidth(maxString);
    g.drawString(maxString, width - 2 - swidth, 23);
    g.dispose();
}

From source file:org.apache.pdfbox.rendering.TilingPaint.java

@Override
public int getTransparency() {
    return Transparency.TRANSLUCENT;
}

From source file:org.eevolution.form.WCRP.java

private void renderChart(JFreeChart jchart) {

    BufferedImage bi = jchart.createBufferedImage(700, 500, Transparency.TRANSLUCENT, null);
    try {//from   w  ww  .  j a v a 2  s. com
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage image = new AImage("", bytes);
        chartPanel.removeChild(chart);

        chart = new Image();
        chart.setContent(image);
        chartPanel.appendChild(chart);
        chartPanel.setVisible(true);
    } catch (Exception e) {
    }
}

From source file:org.eevolution.form.WCRPDetail.java

private void renderChart(JFreeChart jchart) {

    BufferedImage bi = jchart.createBufferedImage(700, 500, Transparency.TRANSLUCENT, null);
    try {/* ww w .  j av a 2  s.c  om*/
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage image = new AImage("", bytes);
        mainLayout.removeChild(west);
        chartPanel = new Hbox();
        chart = new Image();
        chart.setContent(image);
        chartPanel.appendChild(chart);

        west = new West();
        west.appendChild(chartPanel);
        west.setSplittable(true);
        west.setSize("70%");
        west.setAutoscroll(true);
        west.setOpen(true);
        mainLayout.appendChild(west);

    } catch (Exception e) {
        log.log(Level.SEVERE, "WCRP.init", e.getMessage());
    }
}