Example usage for java.awt RenderingHints RenderingHints

List of usage examples for java.awt RenderingHints RenderingHints

Introduction

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

Prototype

public RenderingHints(Key key, Object value) 

Source Link

Document

Constructs a new object with the specified key/value pair.

Usage

From source file:gg.msn.ui.panel.MainPanel.java

@Override
public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    super.paintComponent(g2d);
    g2d.setRenderingHints(/*from w w w.  ja v a 2 s  . c  o  m*/
            new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR));

    try {

        ImageIcon icon = ThemeManager.getTheme().get(ThemeManager.MAIN_BACKGROUND);

        if (icon != null) {
            Image image = icon.getImage();
            g2d.drawImage(image, 0, 0, getWidth(), getHeight(), this);
        } else {
            log.warn("image " + icon.getDescription() + " not Found");
        }

        icon = ThemeManager.getTheme().get(ThemeManager.MAIN_IMAGE);

        if (icon != null) {

            Image cartel = icon.getImage();
            g2d.drawImage(cartel, 0 - cartel.getWidth(this) / 10, getHeight() - cartel.getHeight(this), this);
        } else {
            log.warn("image " + icon.getDescription() + " not Found");
        }
    } catch (Exception e) {
        //            log.error(e);
    }
}

From source file:org.freecine.filmscan.ScanStrip.java

/**
 Get the nth frame of the scan//from   w w w .  ja  va 2s.c  o m
 @param n frame to get
 @return RemderedImage based on the sanned strip, rotated and cropped 
 according to frame dimesions. 
 */
public RenderedImage getFrame(int n) {
    if (perforations == null) {
        findPerforations();
    }

    AffineTransform xform = getFrameXform(n);
    RenderedOp rotated = AffineDescriptor.create(stripImage, xform,
            Interpolation.getInstance(Interpolation.INTERP_BICUBIC), null, null);

    ImageLayout layout = new ImageLayout();

    layout.setColorModel(stripImage.getColorModel());
    RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
    RenderedOp background = ConstantDescriptor.create((float) FRAME_WIDTH, (float) FRAME_HEIGHT,
            new Short[] { 0, 0, 0 }, null);
    RenderedOp frame = OverlayDescriptor.create(background, rotated, hints);

    return frame;
}

From source file:lucee.runtime.img.Image.java

public void blur(int blurFactor) throws ExpressionException {
    ParameterBlock params = new ParameterBlock();
    params.addSource(image());//www . j  av a2 s.c o m
    params.add(blurFactor);
    RenderingHints hint = new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(1));
    image(JAI.create("boxfilter", params, hint).getAsBufferedImage());
}

From source file:GUI.Main.java

public static BufferedImage resize(BufferedImage image, int width, int height) {
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TRANSLUCENT);
    Graphics2D g2d = bi.createGraphics();
    g2d.addRenderingHints(//from   www.j a  va  2 s. co m
            new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
    g2d.drawImage(image, 0, 0, width, height, null);
    g2d.dispose();
    return bi;
}

From source file:gui.QTLResultsPanel.java

private JPanel getChart(Trait trait) {
    JFreeChart chart = ChartFactory.createXYLineChart(null, "Position (cM)", "LOD Score", null,
            PlotOrientation.VERTICAL, true, true, false);

    setChartData(chart, trait);//w  ww . j a  v a  2  s .c o m

    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    chart.setRenderingHints(rh);
    chart.removeLegend();

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(new Color(255, 255, 220));
    plot.setDomainGridlinePaint(new Color(128, 128, 128));
    plot.setRangeGridlinePaint(new Color(128, 128, 128));

    ValueAxis axis = plot.getRangeAxis();
    if (trait.maxLOD <= 3) {
        axis.setUpperBound(3);
    }

    PermResult result = trait.getPermResult();
    if (result != null) {
        float[] dashPattern = { 5, 5 };
        BasicStroke s1 = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, dashPattern, 0);

        ValueMarker m1 = new ValueMarker(result.getSig90(), new Color(0, 0, 60), s1, null, null, 1.0f);
        ValueMarker m2 = new ValueMarker(result.getSig95(), new Color(0, 0, 60), s1, null, null, 1.0f);

        plot.addRangeMarker(m1);
        plot.addRangeMarker(m2);

        if (result.getSig95() > trait.maxLOD && result.getSig95() >= 3) {
            axis.setUpperBound(result.getSig95() * (1.05));
        }
    }

    chartPanel = new ChartPanel(chart);
    chartPanel.setPopupMenu(null);
    return chartPanel;
}

From source file:com.simiacryptus.util.Util.java

/**
 * Resize buffered image./* ww  w . j a  v a 2 s . c  o  m*/
 *
 * @param image the image
 * @return the buffered image
 */
@Nullable
public static BufferedImage resize(@Nullable final BufferedImage image) {
    if (null == image)
        return image;
    final int width = Math.min(image.getWidth(), 800);
    if (width == image.getWidth())
        return image;
    final int height = image.getHeight() * width / image.getWidth();
    @javax.annotation.Nonnull
    final BufferedImage rerender = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    final Graphics gfx = rerender.getGraphics();
    @javax.annotation.Nonnull
    final RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    ((Graphics2D) gfx).setRenderingHints(hints);
    gfx.drawImage(image, 0, 0, rerender.getWidth(), rerender.getHeight(), null);
    return rerender;
}

From source file:org.photovault.dcraw.RawImage.java

/**
 *     Get a 8 bit gamma corrected version of the image.
 * @param minWidth Minimum width for the image that will be rendered
 * @param minHeight Minimum height for the image that will be rendered
 * @param isLowQualityAcceptable If true, renderer may use optimizations that
 * trade off image quality for speed./*from w w w .j a  v  a 2s. c  o m*/
 * @return The corrected image
 */
public RenderableOp getCorrectedImage(int minWidth, int minHeight, boolean isLowQualityAcceptable) {

    int maxSubsample = 1;
    if (minWidth > 0 && minHeight > 0) {
        while (width >= minWidth * 2 * maxSubsample && height >= minHeight * 2 * maxSubsample) {
            maxSubsample *= 2;
        }
    }
    if (rawImage == null || maxSubsample < subsample) {
        // dcraw.setHalfSize( isHalfSizeEnough );
        if (maxSubsample == 1 && subsample > 1) {
            // The image has been loaded with 1/2 resolution so reloading
            // cannot be avoided
            closeRaw();
        }
        subsample = maxSubsample;
        loadRawImage();
        correctedImage = null;
    }
    if (correctedImage == null) {
        RenderingHints nonCachedHints = new RenderingHints(JAI.KEY_TILE_CACHE, null);

        // TODO: Why setting color model as a rendering hint produces black image???
        RawConvDescriptor.register();
        ParameterBlock pb = new ParameterBlockJAI("RawConv");
        pb.setSource(wbAdjustedRawImage, 0);
        pb.set(white, 0);
        pb.set(black, 1);
        pb.set(highlightCompression, 2);
        rawConverter = JAI.createRenderable("RawConv", pb, nonCachedHints);
        rawConverter.setProperty("org.photovault.opname", "raw_toneadj_image");
        applyExposureSettings();

        // Convert from linear to gamma corrected
        createGammaLut();
        LookupTableJAI jailut = new LookupTableJAI(gammaLut);
        correctedImage = LookupDescriptor.createRenderable(rawConverter, jailut, null);
        correctedImage.setProperty("org.photovault.opname", "gamma_lut_image");
        // Store the color model of the image
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        cm = new ComponentColorModel(cs, new int[] { 8, 8, 8 }, false, false, Transparency.OPAQUE,
                DataBuffer.TYPE_BYTE);

    }
    return correctedImage;
}

From source file:org.esa.s2tbx.dataio.s2.ortho.Sentinel2OrthoProductReader.java

private void scaleBands(Product product, List<BandInfo> bandInfoList) throws IOException {

    // In MultiResolution mode, all bands are kept at their native resolution
    if (isMultiResolution()) {
        return;/*from ww  w . j  a v a2  s  .  c  o  m*/
    }

    // Find a reference band for rescaling the bands at other resolution
    MultiLevelImage targetImage = null;
    for (BandInfo bandInfo : bandInfoList) {
        if (bandInfo.getBandInformation().getResolution() == getProductResolution()) {
            Band referenceBand = product.getBand(bandInfo.getBandInformation().getPhysicalBand());
            targetImage = referenceBand.getSourceImage();
            break;
        }
    }

    // If the product only has a subset of bands, we may not find what we are looking for
    if (targetImage == null) {
        String error = String.format(
                "Products with no bands at %s m resolution currently cannot be read by the %s m reader",
                getProductResolution().resolution, getProductResolution().resolution);
        throw new IOException(error);
    }

    for (Band band : product.getBands()) {
        final MultiLevelImage sourceImage = band.getSourceImage();

        if (sourceImage.getWidth() == product.getSceneRasterWidth()
                && sourceImage.getHeight() == product.getSceneRasterHeight()) {
            // Do not rescaled band which are already at the correct resolution
            continue;
        }

        ImageLayout imageLayout = new ImageLayout();
        ImageManager.getPreferredTileSize(product);
        final RenderingHints renderingHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, imageLayout);
        float[] scalings = new float[2];
        scalings[0] = product.getSceneRasterWidth() / (float) sourceImage.getWidth();
        scalings[1] = product.getSceneRasterHeight() / (float) sourceImage.getHeight();
        PlanarImage scaledImage = SourceImageScaler.scaleMultiLevelImage(targetImage, sourceImage, scalings,
                null, renderingHints, band.getNoDataValue(),
                Interpolation.getInstance(Interpolation.INTERP_NEAREST));
        band.setSourceImage(scaledImage);
    }
}

From source file:org.photovault.image.ImageIOImage.java

/**
 Load the image and/or metadata/*from  w ww . java2  s  .  c o m*/
 @param loadImage Load the image pixel data if <CODE>true</CODE>
 @param loadMetadata Load image metadata if <CODE>true</CODE>.
 @param minWidth Minimum width of the loaded image
 @param minHeight Minimum height of the loaded image
 @param isLowQualityAllowed If <code>true</code>, use larger subsampling 
 to speed up loading.
 */
private void load(boolean loadImage, boolean loadMetadata, int minWidth, int minHeight,
        boolean isLowQualityAllowed) {
    if (f != null && f.canRead()) {
        ImageReader reader = getImageReader(f);
        if (reader != null) {
            log.debug("Creating stream");
            ImageInputStream iis = null;
            try {
                iis = ImageIO.createImageInputStream(f);
                reader.setInput(iis, false, false);
                width = reader.getWidth(0);
                height = reader.getHeight(0);
                if (loadImage) {
                    RenderedImage ri = null;
                    if (isLowQualityAllowed) {
                        ri = readExifThumbnail(f);
                        if (ri == null || !isOkForThumbCreation(ri.getWidth(), ri.getHeight(), minWidth,
                                minHeight, reader.getAspectRatio(0), 0.01)) {
                            /*
                             EXIF thumbnail either did not exist or was unusable,
                             try to read subsampled version of original
                             */
                            ri = readSubsampled(reader, minWidth, minHeight);
                        }
                    } else {
                        /*
                         High quality image is requested.
                                 
                         If the image is very large, use subsampling anyway
                         to decrease memory consumption & speed up interactive 
                         operations. Anyway, most often user just views image 
                         at screen resolution
                         */
                        ImageReadParam param = reader.getDefaultReadParam();

                        if (minWidth * 2 < width && minHeight * 2 < height) {
                            param.setSourceSubsampling(2, 2, 0, 0);
                        }
                        ri = reader.read(0, param);

                    }
                    if (ri != null) {
                        /*
                         TODO: JAI seems to have problems in doing convolutions
                         for large image tiles. Split image to reasonably sized
                         tiles as a workaround for this.
                         */
                        ri = new TiledImage(ri, 256, 256);
                        image = new RenderedImageAdapter(ri);
                        originalSampleModel = image.getSampleModel();
                        originalColorModel = image.getColorModel();
                        final float[] DEFAULT_KERNEL_1D = { 0.25f, 0.5f, 0.25f };
                        ParameterBlock pb = new ParameterBlock();
                        KernelJAI kernel = new KernelJAI(DEFAULT_KERNEL_1D.length, DEFAULT_KERNEL_1D.length,
                                DEFAULT_KERNEL_1D.length / 2, DEFAULT_KERNEL_1D.length / 2, DEFAULT_KERNEL_1D,
                                DEFAULT_KERNEL_1D);
                        pb.add(kernel);
                        BorderExtender extender = BorderExtender.createInstance(BorderExtender.BORDER_COPY);
                        RenderingHints hints = JAI.getDefaultInstance().getRenderingHints();
                        if (hints == null) {
                            hints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, extender);
                        } else {
                            hints.put(JAI.KEY_BORDER_EXTENDER, extender);
                        }

                        RenderedOp filter = new RenderedOp("convolve", pb, hints);
                        // javax.media.jai.operator.BoxFilterDescriptor.create( null, new Integer(2), new Integer(2), new Integer(0), new Integer(0), null );

                        // Add the subsampling operation.
                        pb = new ParameterBlock();
                        pb.addSource(filter);
                        pb.add(new Float(0.5F)).add(new Float(0.5F));
                        pb.add(new Float(0.0F)).add(new Float(0.0F));
                        pb.add(Interpolation.getInstance(Interpolation.INTERP_NEAREST));
                        RenderedOp downSampler = new RenderedOp("scale", pb, null);

                        renderableImage = RenderableDescriptor.createRenderable(image, downSampler, null, null,
                                null, null, null);
                    } else {
                        image = null;
                        renderableImage = null;
                    }
                    imageIsLowQuality = isLowQualityAllowed;
                }
                if (loadMetadata) {
                    readImageMetadata(reader);
                }
            } catch (Exception ex) {
                log.warn(ex.getMessage());
                ex.printStackTrace();
                return;
            }
        }
    }
}

From source file:jboost.visualization.HistogramFrame.java

private JFreeChart createRocChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYLineChart("ROC", // chart title
            "False positive rate", // x axis label
            "True positive rate", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include
            // legend
            true, // tooltips
            false // urls
    );/*from w w w. ja v a  2s.  com*/

    chart.setAntiAlias(false);
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    chart.setRenderingHints(hints);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    lower_tprMarker = new ValueMarker(0.5);
    lower_tprMarker.setPaint(Color.blue);
    lower_fprMarker = new ValueMarker(0.5);
    lower_fprMarker.setPaint(Color.blue);
    plot.addRangeMarker(lower_tprMarker);
    plot.addDomainMarker(lower_fprMarker);

    upper_tprMarker = new ValueMarker(0.5);
    upper_tprMarker.setPaint(Color.red);
    upper_fprMarker = new ValueMarker(0.5);
    upper_fprMarker.setPaint(Color.red);
    plot.addRangeMarker(upper_tprMarker);
    plot.addDomainMarker(upper_fprMarker);

    return chart;

}