List of usage examples for java.awt RenderingHints VALUE_RENDER_QUALITY
Object VALUE_RENDER_QUALITY
To view the source code for java.awt RenderingHints VALUE_RENDER_QUALITY.
Click Source Link
From source file:com.sdk.connector.chart.CoherenceDomainRenderer.java
public CoherenceDomainRenderer(final String title, JPanel panel, String side) { sdf = Protocol.getInstance().getTimestampFormat(); serieFFT.setKey(side + " FFT Based"); serieLomb.setKey(side + " Lomb Based"); serieMemse.setKey(side + " AR Based"); dataset.addSeries(serieFFT);/*from w w w . j ava 2s. c o m*/ dataset.addSeries(serieLomb); dataset.addSeries(serieMemse); chart = ChartFactory.createTimeSeriesChart(title, java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("coherence.xlabel"), java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("coherence.ylabel"), dataset, true, true, false); chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); chart.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); chart.getRenderingHints().put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); chart.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); chart.getRenderingHints().put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); chart.getRenderingHints().put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); chart.getRenderingHints().put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100); //chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.GREEN)); // chart.setBackgroundPaint(new Color(220,255,220,0)); //chart.setBackgroundImage(new javax.swing.ImageIcon(getClass().getResource("/com/sdk/connector/resources/background.png")).getImage()); chart.addSubtitle(rangeAnnotation); plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, sdf, new DecimalFormat("0.00"))); renderer.setSeriesOutlinePaint(0, Color.BLACK); if (side.startsWith( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("side.left"))) { renderer.setSeriesPaint(0, Color.BLUE); leftSide = true; } else { renderer.setSeriesPaint(0, Color.RED); leftSide = false; } renderer.setSeriesShape(0, new Ellipse2D.Double(-1.0, -1.0, 3.0, 3.0)); DateTickUnit dtUnit = new DateTickUnit(DateTickUnitType.MINUTE, 1, tickSDF); final DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); domainAxis.setTickUnit(dtUnit); // ValueAxis axis = plot.getDomainAxis(); // axis = plot.getRangeAxis(); // ((NumberAxis) axis).setTickUnit(new NumberTickUnit(100)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f)); // plot.getRenderer().setSeriesStroke(1, new BasicStroke(1.0f)); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("message.wait")); plot.setRangePannable(true); plot.setDomainPannable(true); Color color1 = new Color(0, 0, 0, 24); Color color2 = new Color(255, 255, 255, 24); GradientPaint gp = new GradientPaint(0, 0, color1, 0, 0, color2); plot.setBackgroundPaint(gp); chartPanel = new ChartPanel(chart); panel.setLayout(new GridLayout(0, 1)); panel.add(chartPanel); panel.repaint(); panel.revalidate(); }
From source file:com.alibaba.simpleimage.ScaleTest.java
public PlanarImage doScaleNearest(PlanarImage op) throws Exception { ParameterBlock pb = new ParameterBlock(); pb.addSource(op);/*ww w. j a v a 2 s. c o m*/ pb.add(scale); pb.add(scale); pb.add(0.0F); pb.add(0.0F); pb.add(Interpolation.getInstance(Interpolation.INTERP_NEAREST)); RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); op = JAI.create("scale", pb, qualityHints); return op; }
From source file:business.model.CaptchaModel.java
/** * * @param CaptchaText//from w w w .j av a 2 s .c om * @return */ public static BufferedImage CreateCaptchaImageOld(String CaptchaText) { BufferedImage localBufferedImage = new BufferedImage(width, height, 1); try { Graphics2D localGraphics2D = localBufferedImage.createGraphics(); // List<Font> fonts = FontFactory.getListFont(); List<Font> fonts = new ArrayList<Font>(); if (fonts.isEmpty()) { fonts.add(new Font("Nimbus Roman No9 L", 1, 30)); fonts.add(new Font("VN-NTime", 1, 30)); fonts.add(new Font("DT-Times", 1, 30)); fonts.add(new Font("Times New Roman", 1, 30)); fonts.add(new Font("Vni-Book123", 1, 30)); fonts.add(new Font("VNI-Centur", 1, 30)); fonts.add(new Font("DT-Brookly", 1, 30)); } // fonts.add(loadFont("BINHLBI.TTF")); RenderingHints localRenderingHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); localRenderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); localGraphics2D.setRenderingHints(localRenderingHints); localGraphics2D.fillRect(0, 0, width, height); localGraphics2D.setColor(new Color(50, 50, 50)); Random localRandom = new Random(); int i = 0; int j = 0; for (int k = 0; k < CaptchaText.length(); k++) { i += 25 + Math.abs(localRandom.nextInt()) % 5; j = 25 + Math.abs(localRandom.nextInt()) % 20; int tmp = localRandom.nextInt(fonts.size() - 1); localGraphics2D.setFont(fonts.get(tmp)); localGraphics2D.drawChars(CaptchaText.toCharArray(), k, 1, i, j); } localBufferedImage = getDistortedImage(localBufferedImage); Graphics2D localGraphics2D2 = localBufferedImage.createGraphics(); localGraphics2D2.setRenderingHints(localRenderingHints); // localGraphics2D2.fillRect(0, 0, width, height); localGraphics2D2.setColor(new Color(50, 50, 50)); CubicCurve2D c = new CubicCurve2D.Double();// draw QuadCurve2D.Float with set coordinates for (int l = 0; l < 7; l++) { int x1 = Util.rand(0, width / 2); ; int x2 = Util.rand(width / 2, width); int y1 = Util.rand(0, height); int y2 = Util.rand(0, height); int ctrlx1 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly1 = y1; int ctrlx2 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly2 = y2; c.setCurve(x1, y1, ctrlx2, ctrly2, ctrlx1, ctrly1, x2, y2); localGraphics2D2.draw(c); // localGraphics2D2.drawLine(randomX1(), randomY1(), randomX2(), randomY2()); } localGraphics2D.dispose(); } catch (Exception e) { log.error(e.getMessage(), e); return null; } return localBufferedImage; }
From source file:doge.photo.DogePhotoManipulator.java
private void setGraphicsHints(Graphics2D graphics) { graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); }
From source file:ClipImage.java
public Graphics2D createDemoGraphics2D(Graphics g) { Graphics2D g2 = null;//from w w w .j a v a 2 s. co m if (offImg == null || offImg.getWidth() != w || offImg.getHeight() != h) { offImg = (BufferedImage) createImage(w, h); newBufferedImage = true; } if (offImg != null) { g2 = offImg.createGraphics(); g2.setBackground(getBackground()); } // .. set attributes .. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // .. clear canvas .. g2.clearRect(0, 0, w, h); return g2; }
From source file:com.sdk.connector.chart.TimeDomainRenderer.java
public TimeDomainRenderer(final String title, JPanel panel, String side, String type) { sdf = protocol.getTimestampFormat(); this.side = side + type; this.type = type; serie.setKey(side);//from w w w. ja v a 2 s .co m dataset.addSeries(serie); String legendX = ""; if (type.startsWith(java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("RR"))) { legendX = java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle") .getString("timeRR.ylabel"); } else { legendX = java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle") .getString("timeBC.ylabel"); } chart = ChartFactory.createTimeSeriesChart(title, java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("time.xlabel"), legendX, dataset, true, true, false); chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); chart.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); chart.getRenderingHints().put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); chart.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); chart.getRenderingHints().put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); chart.getRenderingHints().put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); chart.getRenderingHints().put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100); //chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.GREEN)); // chart.setBackgroundPaint(new Color(220,255,220,0)); //chart.setBackgroundImage(new javax.swing.ImageIcon(getClass().getResource("/com/sdk/connector/resources/background.png")).getImage()); chart.addSubtitle(rangeAnnotation); plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, sdf, new DecimalFormat("0.00"))); renderer.setSeriesOutlinePaint(0, Color.BLACK); if (side.startsWith( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("side.left"))) { renderer.setSeriesPaint(0, Color.BLUE); } else { renderer.setSeriesPaint(0, Color.RED); } renderer.setSeriesShape(0, new Ellipse2D.Double(-1.0, -1.0, 3.0, 3.0)); if (type.startsWith(java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("BC"))) { renderer.setSeriesShape(0, new Rectangle2D.Double(-1.0, -1.0, 3.0, 3.0)); } DateTickUnit dtUnit = new DateTickUnit(DateTickUnitType.MINUTE, 1, tickSDF); final DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); domainAxis.setTickUnit(dtUnit); // ValueAxis axis = plot.getDomainAxis(); // axis = plot.getRangeAxis(); // ((NumberAxis) axis).setTickUnit(new NumberTickUnit(100)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f)); // plot.getRenderer().setSeriesStroke(1, new BasicStroke(1.0f)); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("CALIBRATING...")); plot.setRangePannable(true); plot.setDomainPannable(true); Color color1 = new Color(0, 0, 0, 24); Color color2 = new Color(255, 255, 255, 24); GradientPaint gp = new GradientPaint(0, 0, color1, 0, 0, color2); plot.setBackgroundPaint(gp); chartPanel = new ChartPanel(chart); chartPanel.addChartMouseListener(this); panel.setLayout(new GridLayout(0, 1)); panel.add(chartPanel); panel.repaint(); panel.revalidate(); }
From source file:ch.rasc.downloadchart.DownloadChartServlet.java
private static void handleJpg(HttpServletResponse response, byte[] imageData, Integer width, Integer height, String filename, JpegOptions options) throws IOException { response.setContentType("image/jpeg"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + ".jpg\";"); BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData)); Dimension newDimension = calculateDimension(image, width, height); int imgWidth = image.getWidth(); int imgHeight = image.getHeight(); if (newDimension != null) { imgWidth = newDimension.width;/*from w w w . j a v a2s . co m*/ imgHeight = newDimension.height; } BufferedImage newImage = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g = newImage.createGraphics(); g.drawImage(image, 0, 0, imgWidth, imgHeight, Color.BLACK, null); g.dispose(); if (newDimension != null) { g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } try (ImageOutputStream ios = ImageIO.createImageOutputStream(response.getOutputStream())) { Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpg"); ImageWriter writer = iter.next(); ImageWriteParam iwp = writer.getDefaultWriteParam(); iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); if (options != null && options.quality != null && options.quality != 0 && options.quality != 100) { iwp.setCompressionQuality(options.quality / 100f); } else { iwp.setCompressionQuality(1); } writer.setOutput(ios); writer.write(null, new IIOImage(newImage, null, null), iwp); writer.dispose(); } }
From source file:com.alibaba.simpleimage.ScaleTest.java
public PlanarImage doScaleBilinear(PlanarImage op) throws Exception { ParameterBlock pb = new ParameterBlock(); pb.addSource(op);/*w w w . j a va 2s . c om*/ pb.add(scale); pb.add(scale); pb.add(0.0F); pb.add(0.0F); pb.add(Interpolation.getInstance(Interpolation.INTERP_BILINEAR)); RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); op = JAI.create("scale", pb, qualityHints); return op; }
From source file:com.hmsinc.epicenter.spatial.render.SpatialScanRenderer.java
/** * @param context/*from www.ja va 2 s . c o m*/ * @return */ private BufferedImage renderImage(final MapContext context, int width, int height) { logger.trace("Image width: {} height: {}", width, height); final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D graphics2D = (Graphics2D) image.getGraphics(); final GTRenderer renderer = new StreamingRenderer(); final RenderingHints h = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); h.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); h.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); h.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); h.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); renderer.setJava2DHints(h); renderer.setContext(context); renderer.paint(graphics2D, new Rectangle(width, height), context.getAreaOfInterest()); return image; }
From source file:Thumbnail.java
/** * Reads an image in a file and creates a thumbnail in another file. * largestDimension is the largest dimension of the thumbnail, the other dimension is scaled accordingly. * Utilises weighted stepping method to gradually reduce the image size for better results, * i.e. larger steps to start with then smaller steps to finish with. * Note: always writes a JPEG because GIF is protected or something - so always make your outFilename end in 'jpg'. * PNG's with transparency are given white backgrounds *//* w w w. j ava 2s . com*/ public String createThumbnail(String inFilename, String outFilename, int largestDimension) { try { double scale; int sizeDifference, originalImageLargestDim; if (!inFilename.endsWith(".jpg") && !inFilename.endsWith(".jpeg") && !inFilename.endsWith(".gif") && !inFilename.endsWith(".png")) { return "Error: Unsupported image type, please only either JPG, GIF or PNG"; } else { Image inImage = Toolkit.getDefaultToolkit().getImage(inFilename); if (inImage.getWidth(null) == -1 || inImage.getHeight(null) == -1) { return "Error loading file: \"" + inFilename + "\""; } else { //find biggest dimension if (inImage.getWidth(null) > inImage.getHeight(null)) { scale = (double) largestDimension / (double) inImage.getWidth(null); sizeDifference = inImage.getWidth(null) - largestDimension; originalImageLargestDim = inImage.getWidth(null); } else { scale = (double) largestDimension / (double) inImage.getHeight(null); sizeDifference = inImage.getHeight(null) - largestDimension; originalImageLargestDim = inImage.getHeight(null); } //create an image buffer to draw to BufferedImage outImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); //arbitrary init so code compiles Graphics2D g2d; AffineTransform tx; if (scale < 1.0d) //only scale if desired size is smaller than original { int numSteps = sizeDifference / 100; int stepSize = sizeDifference / numSteps; int stepWeight = stepSize / 2; int heavierStepSize = stepSize + stepWeight; int lighterStepSize = stepSize - stepWeight; int currentStepSize, centerStep; double scaledW = inImage.getWidth(null); double scaledH = inImage.getHeight(null); if (numSteps % 2 == 1) //if there's an odd number of steps centerStep = (int) Math.ceil((double) numSteps / 2d); //find the center step else centerStep = -1; //set it to -1 so it's ignored later Integer intermediateSize = originalImageLargestDim, previousIntermediateSize = originalImageLargestDim; Integer calculatedDim; for (Integer i = 0; i < numSteps; i++) { if (i + 1 != centerStep) //if this isn't the center step { if (i == numSteps - 1) //if this is the last step { //fix the stepsize to account for decimal place errors previously currentStepSize = previousIntermediateSize - largestDimension; } else { if (numSteps - i > numSteps / 2) //if we're in the first half of the reductions currentStepSize = heavierStepSize; else currentStepSize = lighterStepSize; } } else //center step, use natural step size { currentStepSize = stepSize; } intermediateSize = previousIntermediateSize - currentStepSize; scale = (double) intermediateSize / (double) previousIntermediateSize; scaledW = (int) scaledW * scale; scaledH = (int) scaledH * scale; outImage = new BufferedImage((int) scaledW, (int) scaledH, BufferedImage.TYPE_INT_RGB); g2d = outImage.createGraphics(); g2d.setBackground(Color.WHITE); g2d.clearRect(0, 0, outImage.getWidth(), outImage.getHeight()); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); tx = new AffineTransform(); tx.scale(scale, scale); g2d.drawImage(inImage, tx, null); g2d.dispose(); inImage = new ImageIcon(outImage).getImage(); previousIntermediateSize = intermediateSize; } } else { //just copy the original outImage = new BufferedImage(inImage.getWidth(null), inImage.getHeight(null), BufferedImage.TYPE_INT_RGB); g2d = outImage.createGraphics(); g2d.setBackground(Color.WHITE); g2d.clearRect(0, 0, outImage.getWidth(), outImage.getHeight()); tx = new AffineTransform(); tx.setToIdentity(); //use identity matrix so image is copied exactly g2d.drawImage(inImage, tx, null); g2d.dispose(); } //JPEG-encode the image and write to file. OutputStream os = new FileOutputStream(outFilename); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os); encoder.encode(outImage); os.close(); } } } catch (Exception ex) { String errorMsg = ""; errorMsg += "<br>Exception: " + ex.toString(); errorMsg += "<br>Cause = " + ex.getCause(); errorMsg += "<br>Stack Trace = "; StackTraceElement stackTrace[] = ex.getStackTrace(); for (int traceLine = 0; traceLine < stackTrace.length; traceLine++) { errorMsg += "<br>" + stackTrace[traceLine]; } return errorMsg; } return ""; //success }