List of usage examples for java.awt RenderingHints KEY_RENDERING
Key KEY_RENDERING
To view the source code for java.awt RenderingHints KEY_RENDERING.
Click Source Link
From source file:org.pentaho.di.core.gui.SwingDirectGC.java
public void setAntialias(boolean antiAlias) { if (antiAlias) { RenderingHints hints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)); hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); // hints.add(new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION, // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)); gc.setRenderingHints(hints);//w ww. j a v a 2 s . c o m } }
From source file:com.funambol.foundation.util.MediaUtils.java
/** * Rotates given buffered image by given amount of degree. * The valid degree values are 0, 90, 180, 270. * If the image is a jpg, the rotation is lossless, exif data are preserved * and image size is almost the same./*w ww. j a v a 2 s .co m*/ * * @param bufImage the buffered image * @param degree amount of degree to apply * @return a buffered image containing rotated image data * @throws PicturesException if amount of degree is invalid or if an * IOException occurs */ private static BufferedImage rotateImage(BufferedImage bufImage, int degree) throws FileDataObjecyUtilsException { degree = degree % 360; int h; int w; switch (degree) { case 0: case 180: h = bufImage.getHeight(); w = bufImage.getWidth(); break; case 90: case 270: h = bufImage.getWidth(); w = bufImage.getHeight(); break; default: throw new FileDataObjecyUtilsException( "Error rotating image since the '" + degree + "' degree value is unsupported"); } BufferedImage out = null; int bufImageType = bufImage.getType(); if (BufferedImage.TYPE_BYTE_INDEXED == bufImageType || BufferedImage.TYPE_BYTE_BINARY == bufImageType) { IndexColorModel model = (IndexColorModel) bufImage.getColorModel(); out = new BufferedImage(w, h, bufImage.getType(), model); } else if (BufferedImage.TYPE_CUSTOM == bufImageType) { // we don't know what type of image it can be // there's a bug in some VM that cause some PNG images to have // type custom: this should take care of this issue //check if we need to have alpha channel boolean alpha = bufImage.getTransparency() != BufferedImage.OPAQUE; if (alpha) { // TYPE_INT_ARGB_PRE gives you smaller output images // than TYPE_INT_ARGB out = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); } else { out = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); } } else { out = new BufferedImage(w, h, bufImage.getType()); } Graphics2D g2d = out.createGraphics(); Map renderingHints = new HashMap(); renderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); renderingHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.setRenderingHints(renderingHints); g2d.rotate(Math.toRadians(degree)); switch (degree) { case 90: g2d.translate(0, -w); break; case 180: g2d.translate(-w, -h); break; case 270: g2d.translate(-h, 0); break; } g2d.drawImage(bufImage, null, 0, 0); g2d.dispose(); return out; }
From source file:MyJava3D.java
public Graphics2D createGraphics2D(int width, int height, BufferedImage bi, Graphics g) { Graphics2D g2 = null;//from ww w . j a v a 2 s . c o m if (bi != null) { g2 = bi.createGraphics(); } else { g2 = (Graphics2D) g; } g2.setBackground(getBackground()); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, AntiAlias); g2.setRenderingHint(RenderingHints.KEY_RENDERING, Rendering); if (clearSurface || clearOnce) { g2.clearRect(0, 0, width, height); clearOnce = false; } if (texture != null) { // set composite to opaque for texture fills g2.setComposite(AlphaComposite.SrcOver); g2.setPaint(texture); g2.fillRect(0, 0, width, height); } if (composite != null) { g2.setComposite(composite); } return g2; }
From source file:org.csstudio.swt.widgets.figures.ImageFigure.java
private void initRenderingHints() { transcoder.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); transcoder.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); transcoder.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); transcoder.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); transcoder.getRenderingHints().put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); }
From source file:net.geoprism.dashboard.DashboardMap.java
private BufferedImage getLegendTitleImage(DashboardLayer layer) { FontMetrics fm;/* ww w .j ava 2s .c o m*/ int textWidth; int textHeight; int textBoxHorizontalPadding = 4; int textBoxVerticalPadding = 4; int borderWidth = 2; int paddedTitleHeight; int paddedTitleWidth; int titleLeftPadding = textBoxHorizontalPadding; BufferedImage newLegendTitleBase; Graphics2D newLegendTitleBaseGraphic = null; try { // Build the Font object Font titleFont = new Font(layer.getName(), Font.BOLD, 14); // Build variables for base legend graphic construction try { newLegendTitleBase = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); newLegendTitleBaseGraphic = newLegendTitleBase.createGraphics(); newLegendTitleBaseGraphic.setFont(titleFont); fm = newLegendTitleBaseGraphic.getFontMetrics(); textHeight = fm.getHeight(); textWidth = fm.stringWidth(layer.getName()); paddedTitleWidth = textWidth + (textBoxHorizontalPadding * 2) + (borderWidth * 2); paddedTitleHeight = textHeight + (textBoxVerticalPadding * 2) + (borderWidth * 2); } finally { // dispose of temporary graphics context if (newLegendTitleBaseGraphic != null) { newLegendTitleBaseGraphic.dispose(); } } titleLeftPadding = ((paddedTitleWidth / 2) - ((textWidth + (textBoxHorizontalPadding * 2) + (borderWidth * 2)) / 2)) + textBoxHorizontalPadding; newLegendTitleBase = new BufferedImage(paddedTitleWidth, paddedTitleHeight, BufferedImage.TYPE_INT_ARGB); newLegendTitleBaseGraphic = newLegendTitleBase.createGraphics(); newLegendTitleBaseGraphic.drawImage(newLegendTitleBase, 0, 0, null); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); newLegendTitleBaseGraphic.setFont(titleFont); // draw title text fm = newLegendTitleBaseGraphic.getFontMetrics(); newLegendTitleBaseGraphic.setColor(Color.WHITE); newLegendTitleBaseGraphic.drawString(layer.getName(), titleLeftPadding, fm.getAscent() + textBoxVerticalPadding); newLegendTitleBaseGraphic.drawImage(newLegendTitleBase, 0, 0, null); } finally { if (newLegendTitleBaseGraphic != null) { newLegendTitleBaseGraphic.dispose(); } } return newLegendTitleBase; }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
public byte[] printImage(float scale, CanvasCommon canvas, Dimension graphsize, String format) throws IOException { int h_margin = 72, v_margin = 72; BufferedImage image = new BufferedImage(graphsize.width + h_margin, graphsize.height + v_margin, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); if (scale > 0) g2.scale(scale, scale);//w w w. ja va 2 s. co m g2.setBackground(Color.WHITE); g2.clearRect(0, 0, image.getWidth(), image.getHeight()); // canvas.paint(g2); Color bgsave = canvas.getBackground(); boolean edsave = canvas.editable; canvas.editable = false; canvas.setBackground(Color.white); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); canvas.paintComponent(g2); canvas.setBackground(bgsave); canvas.editable = edsave; g2.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, format, baos); image = null; Runtime r = Runtime.getRuntime(); r.gc(); return baos.toByteArray(); }
From source file:org.pmedv.blackboard.components.BoardEditor.java
@Override protected void paintComponent(Graphics g) { Boolean useLayerColor = (Boolean) Preferences.values .get("org.pmedv.blackboard.BoardDesignerPerspective.useLayerColor"); // clear all // g.clearRect(0, 0, getWidth(), getHeight()); g.setColor(BLANK);/* www .ja va2 s . c om*/ g.fillRect(0, 0, getWidth(), getHeight()); // some nice anti aliasing... Graphics2D g2 = (Graphics2D) g; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHints(rh); // TODO : Should this be done here? // Sort layers by z-index g2.setColor(Color.LIGHT_GRAY); g2.setStroke(BoardUtil.stroke_1_0f); Collections.sort(model.getLayers()); for (int i = model.getLayers().size() - 1; i >= 0; i--) { // Sort items by z-index Collections.sort(model.getLayers().get(i).getItems()); drawLayer(model.getLayers().get(i), g2); } // draw selection border if (state.equals(SelectionState.DRAGGING_NEW_SELECTION) && button1Pressed) { g2.setColor(Color.GREEN); g2.setStroke(BoardUtil.stroke_1_0f); if (dragStopX < dragStartX && dragStopY > dragStartY) { selectionBorder.setSize(dragStartX - dragStopX, dragStopY - dragStartY); selectionBorder.setLocation(dragStopX, dragStartY); } else if (dragStopY < dragStartY && dragStopX > dragStartX) { selectionBorder.setSize(dragStopX - dragStartX, dragStartY - dragStopY); selectionBorder.setLocation(dragStartX, dragStopY); } else if (dragStopX < dragStartX && dragStopY < dragStartY) { selectionBorder.setSize(dragStartX - dragStopX, dragStartY - dragStopY); selectionBorder.setLocation(dragStopX, dragStopY); } else { selectionBorder.setSize(dragStopX - dragStartX, dragStopY - dragStartY); selectionBorder.setLocation(dragStartX, dragStartY); } g2.draw(selectionBorder); } // display shape currently being drawed if (lineStartX > 0 && lineStartY > 0 && lineStopX > 0 && lineStopY > 0) { if (useLayerColor) g2.setColor(model.getCurrentLayer().getColor()); else g2.setColor(palette.getCurrentColor()); g2.setStroke((BasicStroke) shapesPanel.getThicknessCombo().getSelectedItem()); // draw new line if (editorMode.equals(EditorMode.DRAW_LINE)) { if (useLayerColor) currentDrawingLine.setColor(model.getCurrentLayer().getColor()); else currentDrawingLine.setColor(palette.getCurrentColor()); currentDrawingLine.setStartType((LineEdgeType) shapesPanel.getStartLineCombo().getSelectedItem()); currentDrawingLine.setEndType((LineEdgeType) shapesPanel.getEndLineCombo().getSelectedItem()); currentDrawingLine.setStroke((BasicStroke) shapesPanel.getThicknessCombo().getSelectedItem()); currentDrawingLine.getStart().setLocation(lineStartX, lineStartY); currentDrawingLine.getEnd().setLocation(lineStopX, lineStopY); currentDrawingLine.draw(g2); } else if (editorMode.equals(EditorMode.DRAW_MEASURE)) { currentDrawingLine.setStroke(Measure.DEFAULT_STROKE); currentDrawingLine.getStart().setLocation(lineStartX, lineStartY); currentDrawingLine.getEnd().setLocation(lineStopX, lineStopY); currentDrawingLine.draw(g2); } // draw new box or ellipse else if (editorMode.equals(EditorMode.DRAW_RECTANGLE) || editorMode.equals(EditorMode.DRAW_ELLIPSE)) { int xLoc = lineStartX; int yLoc = lineStartY; int width = lineStopX - lineStartX; int height = lineStopY - lineStartY; ShapeStyle style = (ShapeStyle) shapesPanel.getStyleCombo().getSelectedItem(); if (style == null || style.equals(ShapeStyle.FILLED)) { if (editorMode.equals(EditorMode.DRAW_RECTANGLE)) { g2.fillRect(xLoc, yLoc, width, height); } else { g2.fillOval(xLoc, yLoc, width, height); } } else if (style.equals(ShapeStyle.OUTLINED)) { g2.setStroke((BasicStroke) shapesPanel.getThicknessCombo().getSelectedItem()); if (editorMode.equals(EditorMode.DRAW_RECTANGLE)) { g2.drawRect(xLoc, yLoc, width, height); } else { g2.drawOval(xLoc, yLoc, width, height); } } } } // draw selection handles if (selectedItem != null) { g2.setStroke(BoardUtil.stroke_1_0f); g2.setColor(Color.GREEN); selectedItem.drawHandles(g2, 8); } // draw border if (zoomLayer != null) { TransformUI ui = (TransformUI) (Object) zoomLayer.getUI(); DefaultTransformModel xmodel = (DefaultTransformModel) ui.getModel(); if (xmodel.isMirror()) { g2.setColor(Color.RED); } else { g2.setColor(Color.GREEN); } } else { g2.setColor(Color.GREEN); } g2.setStroke(DEFAULT_STROKE); Rectangle border = new Rectangle(0, 0, model.getWidth() - 1, model.getHeight() - 1); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g2.draw(border); if (model.getType().equals(BoardType.STRIPES) || model.getType().equals(BoardType.HOLES)) { g2.setColor(Color.BLACK); g2.setFont(miniFont); int index = 1; for (int x = 12; x < model.getWidth() - 16; x += 16) { g2.drawString(String.valueOf(index++), x, 8); } index = 1; for (int y = 18; y < model.getHeight(); y += 16) { g2.drawString(String.valueOf(index++), 3, y); } } if (editorMode.equals(EditorMode.CHECK_CONNECTIONS)) { if (connectedLines != null) { for (Line line : connectedLines) { line.drawFat(g2); } } } if (drawing) { g2.setColor(Color.BLUE); g2.setStroke(DEFAULT_STROKE); if (selectedPin != null) { g2.drawRect(lineStopX - 8, lineStopY - 8, 16, 16); } } super.paintComponents(g2); }
From source file:ro.nextreports.engine.exporter.ResultExporter.java
protected byte[] getScaledImage(InputStream is, String name, int width, int height) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {//from ww w.j a v a 2s. c o m BufferedImage img = ImageIO.read(is); if ((img.getWidth() == width) && (img.getHeight() == height)) { // original width and height ImageIO.write(img, "png", baos); } else { int type = img.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : img.getType(); BufferedImage scaledImg = new BufferedImage(width, height, type); Graphics2D gScaledImg = scaledImg.createGraphics(); gScaledImg.setComposite(AlphaComposite.Src); gScaledImg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); gScaledImg.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); gScaledImg.drawImage(img, 0, 0, width, height, null); ImageIO.write(scaledImg, "png", baos); } } catch (IOException ex) { ex.printStackTrace(); LOG.error(ex.getMessage(), ex); throw new IOException("Image '" + name + "' could not be scaled."); } finally { is.close(); } return baos.toByteArray(); }
From source file:ro.nextreports.engine.exporter.ResultExporter.java
private BufferedImage toBufferedImage(Image src) { int w = src.getWidth(null); int h = src.getHeight(null); int type = BufferedImage.TYPE_INT_RGB; BufferedImage dest = new BufferedImage(w, h, type); Graphics2D g2 = dest.createGraphics(); g2.drawImage(src, 0, 0, null);//ww w . j a v a2 s .c o m g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.dispose(); return dest; }
From source file:DefaultGraphics2D.java
/** * Default constructor */ public GraphicContext() { // to workaround a JDK bug hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT); }