List of usage examples for java.awt RenderingHints KEY_ANTIALIASING
Key KEY_ANTIALIASING
To view the source code for java.awt RenderingHints KEY_ANTIALIASING.
Click Source Link
From source file:org.deeplearning4j.examples.multigpu.video.VideoGenerator.java
private static int[] generateVideo(String path, int nFrames, int width, int height, int numShapes, Random r, boolean backgroundNoise, int numDistractorsPerFrame) throws Exception { //First: decide where transitions between one shape and another are double[] rns = new double[numShapes]; double sum = 0; for (int i = 0; i < numShapes; i++) { rns[i] = r.nextDouble();//from w w w .ja v a2 s . c om sum += rns[i]; } for (int i = 0; i < numShapes; i++) rns[i] /= sum; int[] startFrames = new int[numShapes]; startFrames[0] = 0; for (int i = 1; i < numShapes; i++) { startFrames[i] = (int) (startFrames[i - 1] + MIN_FRAMES + rns[i] * (nFrames - numShapes * MIN_FRAMES)); } //Randomly generate shape positions, velocities, colors, and type int[] shapeTypes = new int[numShapes]; int[] initialX = new int[numShapes]; int[] initialY = new int[numShapes]; double[] velocityX = new double[numShapes]; double[] velocityY = new double[numShapes]; Color[] color = new Color[numShapes]; for (int i = 0; i < numShapes; i++) { shapeTypes[i] = r.nextInt(NUM_SHAPES); initialX[i] = SHAPE_MIN_DIST_FROM_EDGE + r.nextInt(width - SHAPE_SIZE - 2 * SHAPE_MIN_DIST_FROM_EDGE); initialY[i] = SHAPE_MIN_DIST_FROM_EDGE + r.nextInt(height - SHAPE_SIZE - 2 * SHAPE_MIN_DIST_FROM_EDGE); velocityX[i] = -1 + 2 * r.nextDouble(); velocityY[i] = -1 + 2 * r.nextDouble(); color[i] = new Color(r.nextFloat(), r.nextFloat(), r.nextFloat()); } //Generate a sequence of BufferedImages with the given shapes, and write them to the video SequenceEncoder enc = new SequenceEncoder(new File(path)); int currShape = 0; int[] labels = new int[nFrames]; for (int i = 0; i < nFrames; i++) { if (currShape < numShapes - 1 && i >= startFrames[currShape + 1]) currShape++; BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = bi.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setBackground(Color.BLACK); if (backgroundNoise) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { bi.setRGB(x, y, new Color(r.nextFloat() * MAX_NOISE_VALUE, r.nextFloat() * MAX_NOISE_VALUE, r.nextFloat() * MAX_NOISE_VALUE).getRGB()); } } } g2d.setColor(color[currShape]); //Position of shape this frame int currX = (int) (initialX[currShape] + (i - startFrames[currShape]) * velocityX[currShape] * MAX_VELOCITY); int currY = (int) (initialY[currShape] + (i - startFrames[currShape]) * velocityY[currShape] * MAX_VELOCITY); //Render the shape switch (shapeTypes[currShape]) { case 0: //Circle g2d.fill(new Ellipse2D.Double(currX, currY, SHAPE_SIZE, SHAPE_SIZE)); break; case 1: //Square g2d.fill(new Rectangle2D.Double(currX, currY, SHAPE_SIZE, SHAPE_SIZE)); break; case 2: //Arc g2d.fill(new Arc2D.Double(currX, currY, SHAPE_SIZE, SHAPE_SIZE, 315, 225, Arc2D.PIE)); break; case 3: //Line g2d.setStroke(lineStroke); g2d.draw(new Line2D.Double(currX, currY, currX + SHAPE_SIZE, currY + SHAPE_SIZE)); break; default: throw new RuntimeException(); } //Add some distractor shapes, which are present for one frame only for (int j = 0; j < numDistractorsPerFrame; j++) { int distractorShapeIdx = r.nextInt(NUM_SHAPES); int distractorX = DISTRACTOR_MIN_DIST_FROM_EDGE + r.nextInt(width - SHAPE_SIZE); int distractorY = DISTRACTOR_MIN_DIST_FROM_EDGE + r.nextInt(height - SHAPE_SIZE); g2d.setColor(new Color(r.nextFloat(), r.nextFloat(), r.nextFloat())); switch (distractorShapeIdx) { case 0: g2d.fill(new Ellipse2D.Double(distractorX, distractorY, SHAPE_SIZE, SHAPE_SIZE)); break; case 1: g2d.fill(new Rectangle2D.Double(distractorX, distractorY, SHAPE_SIZE, SHAPE_SIZE)); break; case 2: g2d.fill(new Arc2D.Double(distractorX, distractorY, SHAPE_SIZE, SHAPE_SIZE, 315, 225, Arc2D.PIE)); break; case 3: g2d.setStroke(lineStroke); g2d.draw(new Line2D.Double(distractorX, distractorY, distractorX + SHAPE_SIZE, distractorY + SHAPE_SIZE)); break; default: throw new RuntimeException(); } } enc.encodeImage(bi); g2d.dispose(); labels[i] = shapeTypes[currShape]; } enc.finish(); //write .mp4 return labels; }
From source file:ImageOps.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); int w = getSize().width; int h = getSize().height; g2.setColor(Color.black);/*from w ww . ja v a 2 s. co m*/ float[][] data = { { 0.1f, 0.1f, 0.1f, // low-pass filter 0.1f, 0.2f, 0.1f, 0.1f, 0.1f, 0.1f }, SHARPEN3x3_3 }; String theDesc[] = { "Convolve LowPass", "Convolve Sharpen", "LookupOp", "RescaleOp" }; for (int i = 0; i < bi.length; i++) { int iw = bi[i].getWidth(this); int ih = bi[i].getHeight(this); int x = 0, y = 0; AffineTransform at = new AffineTransform(); at.scale((w - 14) / 2.0 / iw, (h - 34) / 2.0 / ih); BufferedImageOp biop = null; BufferedImage bimg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB); switch (i) { case 0: case 1: x = i == 0 ? 5 : w / 2 + 3; y = 15; Kernel kernel = new Kernel(3, 3, data[i]); ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); cop.filter(bi[i], bimg); biop = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); break; case 2: x = 5; y = h / 2 + 15; byte chlut[] = new byte[256]; for (int j = 0; j < 200; j++) chlut[j] = (byte) (256 - j); ByteLookupTable blut = new ByteLookupTable(0, chlut); LookupOp lop = new LookupOp(blut, null); lop.filter(bi[i], bimg); biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); break; case 3: x = w / 2 + 3; y = h / 2 + 15; RescaleOp rop = new RescaleOp(1.1f, 20.0f, null); rop.filter(bi[i], bimg); biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); } g2.drawImage(bimg, biop, x, y); TextLayout tl = new TextLayout(theDesc[i], g2.getFont(), g2.getFontRenderContext()); tl.draw(g2, (float) x, (float) y - 4); } }
From source file:nz.ac.massey.cs.gql4jung.browser.resultviews.GraphBasedResultView.java
@Override public void display(final MotifInstance instance, DirectedGraph<Vertex, Edge> graph) { DirectedGraph<VisualVertex, VisualEdge> g = instance == null ? new DirectedSparseGraph<VisualVertex, VisualEdge>() : this.asGraph(instance); //SimpleGraphView sgv = new SimpleGraphView(); //We create our graph in here // The Layout<V, E> is parameterized by the vertex and edge types Layout<VisualVertex, VisualEdge> layout = settings.getLayout(g); layout.setSize(graphPane.getSize()); VisualizationViewer<VisualVertex, VisualEdge> vv = new VisualizationViewer<VisualVertex, VisualEdge>( layout);/*from w w w . j a va 2s . c o m*/ if (!settings.isUseAntiAliasing()) { Map hints = new HashMap(); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); vv.setRenderingHints(hints); } configureRenderer(vv.getRenderContext(), instance); vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); vv.setPreferredSize(graphPane.getSize()); //Sets the viewing area size vv.setBackground(settings.getBackground()); graphPane.removeAll(); graphPane.add(vv); graphPane.revalidate(); // pick the vertices that are part of the pattern - this brings them into the foreground /* for (VisualVertex v:g.getVertices()){ if (v.isInMotif()) { vv.getPickedVertexState().pick(v,true); } } */ //vv.addMouseListener(popupListener); // Create a graph mouse and add it to the visualization component DefaultModalGraphMouse gm = new DefaultModalGraphMouse(); gm.setMode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode.PICKING); vv.setGraphMouse(gm); vv.setVertexToolTipTransformer(new Transformer<VisualVertex, String>() { @Override public String transform(VisualVertex v) { return getToolTip(v); } }); }
From source file:org.apache.pdflens.views.pagesview.PageDrawer.java
/** * This will draw the page to the requested context. * * @param g The graphics context to draw onto. * @param p The page to draw./*from www . ja va 2s . co m*/ * @param pageDimension The size of the page to draw. * * @throws IOException If there is an IO error while drawing the page. */ public void drawPage(Graphics g, PDPage p, Dimension pageDimension) throws IOException { graphics = (Graphics2D) g; page = p; pageSize = pageDimension; graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); // Only if there is some content, we have to process it. // Otherwise we are done here and we will produce an empty page if (page.getContents() != null) { PDResources resources = page.findResources(); processStream(page, resources, page.getContents().getStream()); } List annotations = page.getAnnotations(); for (int i = 0; i < annotations.size(); i++) { PDAnnotation annot = (PDAnnotation) annotations.get(i); PDRectangle rect = annot.getRectangle(); String appearanceName = annot.getAppearanceStream(); PDAppearanceDictionary appearDictionary = annot.getAppearance(); if (appearDictionary != null) { if (appearanceName == null) { appearanceName = "default"; } Map appearanceMap = appearDictionary.getNormalAppearance(); PDAppearanceStream appearance = (PDAppearanceStream) appearanceMap.get(appearanceName); if (appearance != null) { g.translate((int) rect.getLowerLeftX(), (int) -rect.getLowerLeftY()); processSubStream(page, appearance.getResources(), appearance.getStream()); g.translate((int) -rect.getLowerLeftX(), (int) +rect.getLowerLeftY()); } } } }
From source file:org.eqaula.glue.faces.MethodPrinter.java
public Method printToDownload(Method method) { try {/*from www . j a v a 2s. com*/ if (Method.Type.SEMAPHORE.equals(method.getMethodType())) { // So, browser is requesting the image. Get ID value from actual request param. BufferedImage bufferedImg = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bufferedImg.createGraphics(); String color = "gray"; //Default color if (!method.getWrappers().isEmpty()) { color = method.getWrappers().get(0).getValue(); } Field field = Class.forName("java.awt.Color").getField(color); g2.setColor((Color) field.get(null)); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Ellipse2D.Float sign1 = new Ellipse2D.Float(0F, 0F, 32F, 32F); g2.fill(sign1); //g2.drawString(method.getTarget().getCurrentValue().toString(), 0, 10); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(bufferedImg, "png", os); writeStreamedContentToFile(method, new ByteArrayInputStream(os.toByteArray())); } } catch (Exception e) { e.printStackTrace(); } return method; }
From source file:Starry.java
public void paintComponent(Graphics g) { super.paintComponent(g); setBackground(Color.white);/*ww w. j ava2 s. c o m*/ w = getSize().width; h = getSize().height; Graphics2D g2; g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); FontRenderContext frc = g2.getFontRenderContext(); Font f = new Font("Helvetica", 1, w / 10); String s = new String("The Starry Night"); TextLayout textTl = new TextLayout(s, f, frc); AffineTransform transform = new AffineTransform(); Shape outline = textTl.getOutline(null); Rectangle r = outline.getBounds(); transform = g2.getTransform(); transform.translate(w / 2 - (r.width / 2), h / 2 + (r.height / 2)); g2.transform(transform); g2.setColor(Color.blue); g2.draw(outline); g2.setClip(outline); g2.drawImage(img, r.x, r.y, r.width, r.height, this); }
From source file:lk.ac.mrt.projectx.buildex.complex.FormalVerifier.java
/** * Creates a new fast scatter plot demo. * * @param title the frame title./*from w w w . ja v a 2s. c o m*/ */ public FormalVerifier(final String title, final String lblx, final String lbly) throws IOException { super(title); populateData(); final NumberAxis domainAxis = new NumberAxis(lblx); domainAxis.setAutoRangeIncludesZero(false); final NumberAxis rangeAxis = new NumberAxis(lbly); rangeAxis.setAutoRangeIncludesZero(false); final FastScatterPlot plot = new FastScatterPlot(this.data, domainAxis, rangeAxis); final JFreeChart chart = new JFreeChart(title, plot); // chart.setLegend(null); // force aliasing of the rendered content.. chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final ChartPanel panel = new ChartPanel(chart, true); panel.setPreferredSize(new java.awt.Dimension(800, 600)); // panel.setHorizontalZoom(true); // panel.setVerticalZoom(true); panel.setMinimumDrawHeight(10); panel.setMaximumDrawHeight(3000); panel.setMinimumDrawWidth(20); panel.setMaximumDrawWidth(3000); setContentPane(panel); //TODO : Print ChartUtilities.saveChartAsJPEG( new File("F:\\FYP2\\FinalP\\graphs\\Twirl" + System.currentTimeMillis() + ".jpg"), chart, 800, 600); }
From source file:game.com.HandleUploadGameThumbServlet.java
public static BufferedImage resizeImage(final Image image, int width, int height) { final BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); final Graphics2D graphics2D = bufferedImage.createGraphics(); graphics2D.setComposite(AlphaComposite.Src); //below three lines are for RenderingHints for better image quality at cost of higher processing time graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.drawImage(image, 0, 0, width, height, null); graphics2D.dispose();/* www.j ava 2 s . c o m*/ return bufferedImage; }
From source file:org.springframework.cloud.stream.app.pose.estimation.processor.PoseEstimateOutputMessageBuilder.java
private byte[] drawPoses(byte[] imageBytes, List<Body> bodies) throws IOException { if (bodies != null) { BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(imageBytes)); Graphics2D g = originalImage.createGraphics(); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Stroke stroke = g.getStroke(); g.setStroke(new BasicStroke(this.poseProperties.getDrawLineWidth())); for (Body body : bodies) { for (Limb limb : body.getLimbs()) { Color limbColor = findLimbColor(body, limb); Part from = limb.getFromPart(); Part to = limb.getToPart(); if (limb.getLimbType() != Model.LimbType.limb17 && limb.getLimbType() != Model.LimbType.limb18) { g.setColor(limbColor); g.draw(new Line2D.Double(from.getNormalizedX(), from.getNormalizedY(), to.getNormalizedX(), to.getNormalizedY())); }/*from ww w.jav a 2s . co m*/ g.setStroke(new BasicStroke(1)); drawPartOval(from, this.poseProperties.getDrawPartRadius(), g); drawPartOval(to, this.poseProperties.getDrawPartRadius(), g); g.setStroke(new BasicStroke(this.poseProperties.getDrawLineWidth())); } } g.setStroke(stroke); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(originalImage, IMAGE_FORMAT, baos); baos.flush(); imageBytes = baos.toByteArray(); baos.close(); g.dispose(); } return imageBytes; }
From source file:edu.ku.brc.ui.GradiantButton.java
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = this.getWidth(); int h = this.getHeight(); drawButtonBody(g2, w, h, getForeground()); if (pressed) { g2.translate(1, 1);/*from w w w .j a v a 2 s .c om*/ } String text = getText(); if (isNotEmpty(text)) { drawText(g2, w, h, getText()); } Icon roIcon = getRolloverIcon(); Icon paintedIcon = isHover && roIcon != null ? roIcon : icon; if (paintedIcon != null) { //Graphics2D g2 = (Graphics2D) g.create(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, iconAlpha)); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); paintedIcon.paintIcon(this, g2, (w - icon.getIconWidth()) / 2, (h - icon.getIconHeight()) / 2); } }