Example usage for java.awt RenderingHints VALUE_RENDER_SPEED

List of usage examples for java.awt RenderingHints VALUE_RENDER_SPEED

Introduction

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

Prototype

Object VALUE_RENDER_SPEED

To view the source code for java.awt RenderingHints VALUE_RENDER_SPEED.

Click Source Link

Document

Rendering hint value -- rendering algorithms are chosen with a preference for output speed.

Usage

From source file:Main.java

/**
 * //from w  w  w.  j  a  v a2 s .  c o m
 * @param g
 * @param antiAlias
 * @param textAntiAlias
 */
public static void setAntiAlias(Graphics2D g, boolean antiAlias, boolean textAntiAlias) {
    g.setRenderingHint(RenderingHints.KEY_RENDERING,
            (antiAlias) ? RenderingHints.VALUE_RENDER_QUALITY : RenderingHints.VALUE_RENDER_SPEED);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            (antiAlias) ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            (textAntiAlias) ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
}

From source file:juicebox.mapcolorui.HeatmapRenderer.java

public boolean render(int originX, int originY, int width, int height, final MatrixZoomData zd,
        final MatrixZoomData controlZD, final MatrixType displayOption,
        final NormalizationType normalizationType, final ExpectedValueFunction df, Graphics2D g) {

    g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);

    int chr1 = zd.getChr1Idx();
    int chr2 = zd.getChr2Idx();
    int x = originX;
    int y = originY;

    boolean isWholeGenome = chr1 == 0 && chr2 == 0;
    boolean sameChr = (chr1 == chr2);

    if (sameChr) {
        // Data is transposable, transpose if necessary.  Convention is to use lower diagonal
        if (x > y) {
            //noinspection SuspiciousNameCombination
            x = originY;// w  ww .jav  a 2s. c  o  m
            y = originX;
            int tmp = width;
            width = height;
            height = tmp;
        }
    }

    int maxX = x + width - 1;
    int maxY = y + height - 1;

    if (displayOption == MatrixType.PEARSON) {

        BasicMatrix bm = zd.getPearsons(df);

        ((HiCColorScale) pearsonColorScale).setMin(bm.getLowerValue());
        ((HiCColorScale) pearsonColorScale).setMax(bm.getUpperValue());
        renderMatrix(bm, originX, originY, width, height, pearsonColorScale, g);

    } else {
        // Iterate through blocks overlapping visible region

        List<Block> blocks = zd.getNormalizedBlocksOverlapping(x, y, maxX, maxY, normalizationType);
        if (blocks == null) {
            return false;
        }

        boolean hasControl = controlZD != null
                && (displayOption == MatrixType.CONTROL || displayOption == MatrixType.RATIO);
        Map<Integer, Block> controlBlocks = new HashMap<Integer, Block>();
        if (hasControl) {
            List<Block> ctrls = controlZD.getNormalizedBlocksOverlapping(x, y, maxX, maxY, normalizationType);
            for (Block b : ctrls) {
                controlBlocks.put(b.getNumber(), b);
            }
        }

        String key = zd.getKey() + displayOption;
        ColorScale cs = getColorScale(key, displayOption, isWholeGenome, blocks);

        double averageCount = zd.getAverageCount(); // Will get overwritten for intra-chr
        double ctrlAverageCount = controlZD == null ? 1 : controlZD.getAverageCount();
        for (Block b : blocks) {

            Collection<ContactRecord> recs = b.getContactRecords();
            if (recs != null) {

                Map<String, ContactRecord> controlRecords = new HashMap<String, ContactRecord>();
                if (hasControl) {
                    Block cb = controlBlocks.get(b.getNumber());
                    if (cb != null) {
                        for (ContactRecord ctrlRec : cb.getContactRecords()) {
                            controlRecords.put(ctrlRec.getKey(), ctrlRec);
                        }
                    }
                }

                for (ContactRecord rec : recs) {
                    double score = Double.NaN;
                    if (displayOption == MatrixType.OE || displayOption == MatrixType.EXPECTED) {
                        double expected = 0;
                        if (chr1 == chr2) {
                            if (df != null) {
                                int binX = rec.getBinX();
                                int binY = rec.getBinY();
                                int dist = Math.abs(binX - binY);
                                expected = df.getExpectedValue(chr1, dist);
                            }
                        } else {
                            expected = (averageCount > 0 ? averageCount : 1);
                        }

                        if (displayOption == MatrixType.OE) {
                            score = rec.getCounts() / expected;
                        } else {
                            score = expected;
                        }
                    } else if (displayOption == MatrixType.CONTROL && hasControl) {
                        ContactRecord ctrlRecord = controlRecords.get(rec.getKey());
                        if (ctrlRecord != null)
                            score = ctrlRecord.getCounts();
                    } else if (displayOption == MatrixType.RATIO && hasControl) {
                        ContactRecord ctrlRecord = controlRecords.get(rec.getKey());
                        if (ctrlRecord != null && ctrlRecord.getCounts() > 0) {
                            double num = rec.getCounts() / averageCount;
                            double den = ctrlRecord.getCounts() / ctrlAverageCount;
                            score = num / den;
                        }
                    } else {
                        score = rec.getCounts();
                    }
                    if (Double.isNaN(score))
                        continue;

                    Color color = cs.getColor((float) score);
                    g.setColor(color);

                    int px = rec.getBinX() - originX;
                    int py = rec.getBinY() - originY;
                    if (px > -1 && py > -1 && px <= width && py <= height) {
                        g.fillRect(px, py, HiCGlobals.BIN_PIXEL_WIDTH, HiCGlobals.BIN_PIXEL_WIDTH);
                    }

                    if (sameChr && (rec.getBinX() != rec.getBinY())) {
                        px = (rec.getBinY() - originX);
                        py = (rec.getBinX() - originY);
                        if (px > -1 && py > -1 && px <= width && py <= height) {
                            g.fillRect(px, py, HiCGlobals.BIN_PIXEL_WIDTH, HiCGlobals.BIN_PIXEL_WIDTH);
                        }
                    }
                }
            }
        }
    }
    return true;
}

From source file:com.neophob.sematrix.generator.Textwriter.java

/**
 * create image.//from   w ww.j  a  v  a  2  s. c om
 *
 * @param text the text
 */
public void createTextImage(String text) {
    //only load if needed
    if (StringUtils.equals(text, this.text)) {
        return;
    }

    this.text = text;

    BufferedImage img = new BufferedImage(TEXT_BUFFER_X_SIZE, internalBufferYSize, BufferedImage.TYPE_INT_RGB);

    Graphics2D g2 = img.createGraphics();
    FontRenderContext frc = g2.getFontRenderContext();
    TextLayout layout = new TextLayout(text, font, frc);
    Rectangle2D rect = layout.getBounds();

    int h = (int) (0.5f + rect.getHeight());
    maxXPos = (int) (0.5f + rect.getWidth()) + 5;
    ypos = internalBufferYSize - (internalBufferYSize - h) / 2;

    img = new BufferedImage(maxXPos, internalBufferYSize, BufferedImage.TYPE_INT_RGB);
    g2 = img.createGraphics();

    g2.setColor(color);
    g2.setFont(font);
    g2.setClip(0, 0, maxXPos, internalBufferYSize);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);

    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.drawString(text, xpos, ypos);
    DataBufferInt dbi = (DataBufferInt) img.getRaster().getDataBuffer();
    textBuffer = dbi.getData();
    g2.dispose();

    wait = 0;
    xofs = 0;
    scrollRight = false;
}

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   ww  w . ja  v  a2  s .c om*/

    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;

}

From source file:MyJava3D.java

public void setRendering(boolean rd) {
    Rendering = rd ? RenderingHints.VALUE_RENDER_QUALITY : RenderingHints.VALUE_RENDER_SPEED;
}

From source file:org.forester.archaeopteryx.TreePanel.java

final void setTextAntialias() {
    if ((_phylogeny != null) && !_phylogeny.isEmpty()) {
        if (_phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING) {
            _rendering_hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        } else {// w w w  . j a va2s.co  m
            _rendering_hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
        }
    }
    if (getMainPanel().getOptions().isAntialiasScreen()) {
        if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR) {
            _rendering_hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        } else {
            _rendering_hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        }
        try {
            _rendering_hints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
        } catch (final Throwable e) {
            _rendering_hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        }
    } else {
        _rendering_hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
        _rendering_hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }
}

From source file:org.apache.fop.render.bitmap.AbstractBitmapDocumentHandler.java

/** {@inheritDoc} */
public IFPainter startPageContent() throws IFException {
    int bitmapWidth;
    int bitmapHeight;
    double scale;
    Point2D offset = null;//from  w  ww. j a v  a2s .  co  m
    if (targetBitmapSize != null) {
        //Fit the generated page proportionally into the given rectangle (in pixels)
        double scale2w = 1000 * targetBitmapSize.width / this.currentPageDimensions.getWidth();
        double scale2h = 1000 * targetBitmapSize.height / this.currentPageDimensions.getHeight();
        bitmapWidth = targetBitmapSize.width;
        bitmapHeight = targetBitmapSize.height;

        //Centering the page in the given bitmap
        offset = new Point2D.Double();
        if (scale2w < scale2h) {
            scale = scale2w;
            double h = this.currentPageDimensions.height * scale / 1000;
            offset.setLocation(0, (bitmapHeight - h) / 2.0);
        } else {
            scale = scale2h;
            double w = this.currentPageDimensions.width * scale / 1000;
            offset.setLocation((bitmapWidth - w) / 2.0, 0);
        }
    } else {
        //Normal case: just scale according to the target resolution
        scale = scaleFactor * getUserAgent().getTargetResolution()
                / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
        bitmapWidth = (int) ((this.currentPageDimensions.width * scale / 1000f) + 0.5f);
        bitmapHeight = (int) ((this.currentPageDimensions.height * scale / 1000f) + 0.5f);
    }

    //Set up bitmap to paint on
    this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight);
    Graphics2D graphics2D = this.currentImage.createGraphics();

    // draw page background
    if (!getSettings().hasTransparentPageBackground()) {
        graphics2D.setBackground(getSettings().getPageBackgroundColor());
        graphics2D.setPaint(getSettings().getPageBackgroundColor());
        graphics2D.fillRect(0, 0, bitmapWidth, bitmapHeight);
    }

    //Set rendering hints
    graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    if (getSettings().isAntiAliasingEnabled() && this.currentImage.getColorModel().getPixelSize() > 1) {
        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    } else {
        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    }
    if (getSettings().isQualityRenderingEnabled()) {
        graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    } else {
        graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    }
    graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

    //Set up initial coordinate system for the page
    if (offset != null) {
        graphics2D.translate(offset.getX(), offset.getY());
    }
    graphics2D.scale(scale / 1000f, scale / 1000f);

    return new Java2DPainter(graphics2D, getContext(), getFontInfo());
}

From source file:org.polymap.core.data.feature.FeatureRenderProcessor2.java

protected Image getMap(final Set<ILayer> layers, int width, int height, final ReferencedEnvelope bbox) {
    //        Logger wfsLog = Logging.getLogger( "org.geotools.data.wfs.protocol.http" );
    //        wfsLog.setLevel( Level.FINEST );

    // mapContext
    MapContext mapContext = mapContextRef.get(new Supplier<MapContext>() {
        public MapContext get() {
            log.debug("Creating new MapContext... ");
            // sort z-priority
            TreeMap<String, ILayer> sortedLayers = new TreeMap();
            for (ILayer layer : layers) {
                String uniqueOrderKey = String.valueOf(layer.getOrderKey()) + layer.id();
                sortedLayers.put(uniqueOrderKey, layer);
            }//  w ww . ja  v  a2s  . c o  m
            // add to mapContext
            MapContext result = new DefaultMapContext(bbox.getCoordinateReferenceSystem());
            for (ILayer layer : sortedLayers.values()) {
                try {
                    FeatureSource fs = PipelineFeatureSource.forLayer(layer, false);
                    log.debug("        FeatureSource: " + fs);
                    log.debug("            fs.getName(): " + fs.getName());

                    Style style = layer.getStyle().resolve(Style.class, null);
                    if (style == null) {
                        log.warn("            fs.getName(): " + fs.getName());
                        style = new DefaultStyles().findStyle(fs);
                    }
                    result.addLayer(fs, style);

                    // watch layer for style changes
                    LayerStyleListener listener = new LayerStyleListener(mapContextRef);
                    if (watchedLayers.putIfAbsent(layer, listener) == null) {
                        layer.addPropertyChangeListener(listener);
                    }
                } catch (IOException e) {
                    log.warn(e);
                    // FIXME set layer status and statusMessage
                } catch (PipelineIncubationException e) {
                    log.warn("No pipeline.", e);
                }
            }
            log.debug("created: " + result);
            return result;
        }
    });
    log.debug("using: " + mapContext);

    // render
    //        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    //        GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    //        VolatileImage result = gc.createCompatibleVolatileImage( width, height, Transparency.TRANSLUCENT );

    BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    result.setAccelerationPriority(1);

    final Graphics2D g = result.createGraphics();
    //        log.info( "IMAGE: accelerated=" + result.getCapabilities( g.getDeviceConfiguration() ).isAccelerated() );

    try {
        final StreamingRenderer renderer = new StreamingRenderer();

        // rendering hints
        RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING,
                RenderingHints.VALUE_RENDER_SPEED);
        hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
        hints.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON));

        renderer.setJava2DHints(hints);
        //            g.setRenderingHints( hints );

        // error handler
        renderer.addRenderListener(new RenderListener() {
            int featureCount = 0;

            @Override
            public void featureRenderer(SimpleFeature feature) {
                //                  if (++featureCount == 100) {
                //                      log.info( "Switch off antialiasing!" );
                //                      RenderingHints off = new RenderingHints(
                //                              RenderingHints.KEY_ANTIALIASING,
                //                              RenderingHints.VALUE_ANTIALIAS_OFF );
                //                      renderer.setJava2DHints( off );
                //                      g.setRenderingHints( off );
                //                  }
            }

            @Override
            public void errorOccurred(Exception e) {
                log.error("Renderer error: ", e);
                drawErrorMsg(g, "Fehler bei der Darstellung.", e);
            }
        });

        // render params
        Map rendererParams = new HashMap();
        rendererParams.put("optimizedDataLoadingEnabled", Boolean.TRUE);
        renderer.setRendererHints(rendererParams);

        renderer.setContext(mapContext);
        Rectangle paintArea = new Rectangle(width, height);
        renderer.paint(g, paintArea, bbox);
        return result;
    } catch (Throwable e) {
        log.error("Renderer error: ", e);
        drawErrorMsg(g, null, e);
        return result;
    } finally {
        if (g != null) {
            g.dispose();
        }
    }
}

From source file:org.squidy.designer.shape.VisualShape.java

@Override
protected final void paint(PPaintContext paintContext) {
    super.paint(paintContext);

    Graphics2D g = paintContext.getGraphics();

    // Set default font.
    g.setFont(internalFont);/*from w w  w.  j a v a2s.c  o m*/

    //      if (!renderingHintsSet) {
    if (isRenderPrimitive()) {
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
                RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
        g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
        g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
        g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    } else {
        // Use anti aliasing -> May slow down performance.
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
                RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DEFAULT);
        g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }
    //         renderingHintsSet = true;
    //      }

    // Paint the shapes visual representation.
    paintShape(paintContext);

    // Allows visual debugging if enabled.
    if (DebugConstants.ENABLED) {
        paintDebug(paintContext);
    }
}

From source file:org.vulpe.view.tags.Functions.java

/**
 * This method takes in an image as a byte array (currently supports GIF,
 * JPG, PNG and possibly other formats) and resizes it to have a width no
 * greater than the pMaxWidth parameter in pixels. It converts the image to
 * a standard quality JPG and returns the byte array of that JPG image.
 *
 * @param imageData//from   www. j ava2s  .com
 *            the image data.
 * @param maxWidth
 *            the max width in pixels, 0 means do not scale.
 * @return the resized JPG image.
 * @throws IOException
 *             if the image could not be manipulated correctly.
 */
public static byte[] resizeImageAsJPG(final byte[] imageData, final int maxWidth) throws IOException {
    // Create an ImageIcon from the image data
    final ImageIcon imageIcon = new ImageIcon(imageData);
    int width = imageIcon.getIconWidth();
    if (width == maxWidth) {
        return imageData;
    }
    int height = imageIcon.getIconHeight();
    LOG.debug("imageIcon width: " + width + "  height: " + height);
    // If the image is larger than the max width, we need to resize it
    if (maxWidth > 0 && width > maxWidth) {
        // Determine the shrink ratio
        final double ratio = (double) maxWidth / imageIcon.getIconWidth();
        LOG.debug("resize ratio: " + ratio);
        height = (int) (imageIcon.getIconHeight() * ratio);
        width = maxWidth;
        LOG.debug("imageIcon post scale width: " + width + "  height: " + height);
    }
    // Create a new empty image buffer to "draw" the resized image into
    final BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    // Create a Graphics object to do the "drawing"
    final Graphics2D g2d = bufferedImage.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    // Draw the resized image
    g2d.drawImage(imageIcon.getImage(), 0, 0, width, height, null);
    g2d.dispose();
    // Now our buffered image is ready
    // Encode it as a JPEG
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(baos);
    encoder.encode(bufferedImage);
    return baos.toByteArray();
}