List of usage examples for java.awt RenderingHints KEY_TEXT_ANTIALIASING
Key KEY_TEXT_ANTIALIASING
To view the source code for java.awt RenderingHints KEY_TEXT_ANTIALIASING.
Click Source Link
From source file:org.tinymediamanager.ui.components.ImageLabel.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (scaledImage != null) { int originalWidth = scaledImage.getWidth(null); int originalHeight = scaledImage.getHeight(null); // calculate new height/width int newWidth = 0; int newHeight = 0; int offsetX = 0; int offsetY = 0; if (drawBorder && !drawFullWidth) { Point size = ImageCache.calculateSize(this.getWidth() - 8, this.getHeight() - 8, originalWidth, originalHeight, true); // calculate offsets if (position == Position.TOP_RIGHT || position == Position.BOTTOM_RIGHT) { offsetX = this.getWidth() - size.x - 8; }//from www . ja va 2 s . co m if (position == Position.BOTTOM_LEFT || position == Position.BOTTOM_RIGHT) { offsetY = this.getHeight() - size.y - 8; } if (position == Position.CENTER) { offsetX = (this.getWidth() - size.x - 8) / 2; offsetY = (this.getHeight() - size.y - 8) / 2; } newWidth = size.x; newHeight = size.y; // when the image size differs too much - reload and rescale the original image recreateScaledImageIfNeeded(originalWidth, originalHeight, newWidth, newHeight); g.setColor(Color.BLACK); g.drawRect(offsetX, offsetY, size.x + 7, size.y + 7); g.setColor(Color.WHITE); g.fillRect(offsetX + 1, offsetY + 1, size.x + 6, size.y + 6); // g.drawImage(Scaling.scale(originalImage, newWidth, newHeight), offsetX + 4, offsetY + 4, newWidth, newHeight, this); g.drawImage(scaledImage, offsetX + 4, offsetY + 4, newWidth, newHeight, this); } else { Point size = null; if (drawFullWidth) { size = new Point(this.getWidth(), this.getWidth() * originalHeight / originalWidth); } else { size = ImageCache.calculateSize(this.getWidth(), this.getHeight(), originalWidth, originalHeight, true); } // calculate offsets if (position == Position.TOP_RIGHT || position == Position.BOTTOM_RIGHT) { offsetX = this.getWidth() - size.x; } if (position == Position.BOTTOM_LEFT || position == Position.BOTTOM_RIGHT) { offsetY = this.getHeight() - size.y; } if (position == Position.CENTER) { offsetX = (this.getWidth() - size.x) / 2; offsetY = (this.getHeight() - size.y) / 2; } newWidth = size.x; newHeight = size.y; // when the image size differs too much - reload and rescale the original image recreateScaledImageIfNeeded(originalWidth, originalHeight, newWidth, newHeight); // g.drawImage(Scaling.scale(originalImage, newWidth, newHeight), offsetX, offsetY, newWidth, newHeight, this); g.drawImage(scaledImage, offsetX, offsetY, newWidth, newHeight, this); } } else { // draw border and background if (drawBorder) { g.setColor(Color.BLACK); g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1); if (getParent().isOpaque()) { g.setColor(getParent().getBackground()); g.fillRect(1, 1, this.getWidth() - 2, this.getHeight() - 2); } } // calculate diagonal int diagonalSize = (int) Math .sqrt(this.getWidth() * this.getWidth() + this.getHeight() * this.getHeight()); // draw text String text = ""; if (alternativeText != null) { text = alternativeText; } else { text = BUNDLE.getString("image.nonefound"); //$NON-NLS-1$ } if (!getParent().isOpaque()) { text = ""; } Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); AffineTransform orig = g2.getTransform(); AffineTransform at = new AffineTransform(orig); at.translate(0, this.getHeight()); at.rotate(this.getWidth(), -this.getHeight()); g2.setTransform(at); g2.setColor(Color.BLACK); g2.setFont(FONT); FontMetrics fm = g2.getFontMetrics(); int x = (diagonalSize - fm.stringWidth(text)) / 2; int y = (fm.getAscent() - fm.getDescent()) / 2; g2.drawString(text, x, y); // g2.drawLine(0, 0, diagonalSize, 0); at.translate(0, -this.getHeight()); g2.setTransform(orig); } }
From source file:org.tros.logo.swing.LogoPanel.java
@Override public void drawString(final String message) { Drawable command = new Drawable() { @Override//from ww w . j a v a2 s . co m public void draw(Graphics2D g2, TurtleState turtleState) { if (!turtleState.penup) { AffineTransform saveXform = g2.getTransform(); //double offsetAngle = (Math.PI / 2.0); double offsetAngle = 0; g2.setTransform(AffineTransform.getRotateInstance(turtleState.angle + offsetAngle, turtleState.penX, turtleState.penY)); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); g2.drawString(message, (int) turtleState.penX, (int) turtleState.penY); g2.setTransform(saveXform); } } @Override public void addListener(DrawListener listener) { } @Override public void removeListener(DrawListener listener) { } @Override public Drawable cloneDrawable() { return this; } }; submitCommand(command); }
From source file:org.tros.torgo.Main.java
/** * Initialize the splash graphic.//from ww w . j av a2 s .c o m */ private static void splashInit() { mySplash = SplashScreen.getSplashScreen(); if (mySplash != null) { try { // if there are any problems displaying the splash this will be null splashDimension = mySplash.getSize(); splashImage = ImageIO.read(mySplash.getImageURL()); // create the Graphics environment for drawing status info splashGraphics = mySplash.createGraphics(); font = new Font(Font.SANS_SERIF, Font.PLAIN, 16); splashGraphics.setFont(font); splashGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); // initialize the status info splashText("Starting"); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:processing.app.Theme.java
static public Graphics2D setupGraphics2D(Graphics graphics) { Graphics2D g = (Graphics2D) graphics; if (PreferencesData.getBoolean("editor.antialias")) { g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); }/*from ww w . j a v a 2 s. co m*/ return g; }
From source file:test.unit.be.fedict.eid.applet.service.KmlGeneratorTest.java
@Test public void identityWithAddressAndPhotoKml() throws Exception { // setup//from ww w.j ava 2s.c o m Identity identity = new Identity(); identity.name = "Test Name"; identity.firstName = "Test First name"; identity.dateOfBirth = new GregorianCalendar(); identity.gender = Gender.MALE; Address address = new Address(); address.streetAndNumber = "Test Street 1A"; address.zip = "1234"; address.municipality = "Test Municipality"; BufferedImage image = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) image.getGraphics(); RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHints(renderingHints); graphics.setColor(Color.WHITE); graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1); graphics.setFont(new Font("Dialog", Font.BOLD, 20)); graphics.setColor(Color.BLACK); graphics.drawString("Test Photo", 0, 200 / 2); graphics.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos); byte[] photo = baos.toByteArray(); EIdData eIdData = new EIdData(); eIdData.identity = identity; eIdData.address = address; eIdData.photo = photo; // operate byte[] document = this.testedInstance.generateKml(eIdData); // verify assertNotNull(document); assertTrue(document.length > 0); toTmpFile(document); }
From source file:test.unit.be.fedict.eid.applet.service.PdfGeneratorTest.java
@Test public void identityWithAddressAndPhotoPdf() throws Exception { // setup// ww w . ja v a 2s . c o m Identity identity = new Identity(); identity.name = "Test Name"; identity.firstName = "Test First name"; identity.dateOfBirth = new GregorianCalendar(); identity.gender = Gender.MALE; Address address = new Address(); address.streetAndNumber = "Test Street 1A"; address.zip = "1234"; address.municipality = "Test Municipality"; BufferedImage image = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) image.getGraphics(); RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHints(renderingHints); graphics.setColor(Color.WHITE); graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1); graphics.setFont(new Font("Dialog", Font.BOLD, 20)); graphics.setColor(Color.BLACK); graphics.drawString("Test Photo", 0, 200 / 2); graphics.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos); byte[] photo = baos.toByteArray(); EIdData eIdData = new EIdData(); eIdData.identity = identity; eIdData.address = address; eIdData.photo = photo; // operate byte[] document = this.testedInstance.generatePdf(eIdData); // verify assertNotNull(document); assertTrue(document.length > 0); toTmpFile(document); }
From source file:test.unit.be.fedict.eid.applet.service.VcardGeneratorTest.java
@Test public void identityWithAddressAndPhotoVcard() throws Exception { // setup//from www . j av a 2s .c o m Identity identity = new Identity(); identity.name = "Test Name"; identity.firstName = "Test First name"; identity.dateOfBirth = new GregorianCalendar(); identity.gender = Gender.MALE; Address address = new Address(); address.streetAndNumber = "Test Street 1A"; address.zip = "1234"; address.municipality = "Test Municipality"; BufferedImage image = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) image.getGraphics(); RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHints(renderingHints); graphics.setColor(Color.WHITE); graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1); graphics.setFont(new Font("Dialog", Font.BOLD, 20)); graphics.setColor(Color.BLACK); graphics.drawString("Test Photo", 0, 200 / 2); graphics.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos); byte[] photo = baos.toByteArray(); EIdData eIdData = new EIdData(); eIdData.identity = identity; eIdData.address = address; eIdData.photo = photo; // operate byte[] document = this.testedInstance.generateVcard(eIdData); // verify assertNotNull(document); assertTrue(document.length > 0); toTmpFile(document); }
From source file:uk.co.real_logic.aeron.tools.perf_tools.AeronLatencyUnderLoadPublisher.java
private void generateScatterPlot() throws IOException { final BufferedImage image = new BufferedImage(1800, 1000, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = image.createGraphics(); final FontMetrics fm = g2.getFontMetrics(); final String filename = "throughputency.png"; final File imageFile = new File(filename); final int height = 940; double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (final long timestamp : timestamps) { final double ts = timestamp / 1000.0; if (ts < min) { min = ts;//from w w w . j a v a 2s . c o m } if (ts > max) { max = ts; } } final double stepY = height / max; g2.setColor(Color.white); g2.fillRect(0, 0, 1800, 1000); g2.setColor(Color.black); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.drawString("Latency ScatterPlot (microseconds)", 900 - fm.stringWidth("Latency ScatterPlot (microseconds)") / 2, 20); g2.drawString("" + max, 10, 20); g2.drawLine(100, 20, 100, 960); g2.drawLine(100, 960, 1790, 960); int start = 0; int end = 100; final double width = 1690.0 / 7.0; g2.setColor(Color.red); plotSubset(g2, start, end, "10 msgs/sec", 100, width, stepY, means[0]); start = 100; end = 1100; g2.setColor(Color.green); plotSubset(g2, start, end, "100 msgs/sec", 100 + width, width, stepY, means[1]); start = 1100; end = 11100; g2.setColor(Color.blue); plotSubset(g2, start, end, "1K msgs/sec", 100 + width * 2, width, stepY, means[2]); start = 11100; end = 111100; g2.setColor(Color.cyan); plotSubset(g2, start, end, "10K msgs/sec", 100 + width * 3, width, stepY, means[3]); start = 111100; end = 1111100; g2.setColor(Color.magenta); plotSubset(g2, start, end, "100K msgs/sec", 100 + width * 4, width, stepY, means[4]); start = 1111100; end = 11111100; g2.setColor(Color.yellow); plotSubset(g2, start, end, "1M msgs/sec", 100 + width * 5, width, stepY, means[5]); start = 11111100; end = 41111100; g2.setColor(Color.orange); plotSubset(g2, start, end, "3M msgs/sec", 100 + width * 6, width, stepY, means[6]); ImageIO.write(image, "png", imageFile); }
From source file:z.tool.util.image.ImageUtil.java
/** * ??(???)/* www.j a va 2 s . c om*/ */ public static void mergeResource(int bufferedImageType, InputStream inputStream, ImageType destType, OutputStream outputStream, int newHeight, int newWidth, Mergeable mergeable, Mergeable... mergeables) { if (null == inputStream) { throw new IllegalArgumentException("inputStream is null"); } if (null == destType) { throw new IllegalArgumentException("destType is null"); } if (null == outputStream) { throw new IllegalArgumentException("outputStream is null"); } try { Image srcImage = ImageIO.read(inputStream); // ? int srcImageWidth = srcImage.getWidth(null); int srcImageHeight = srcImage.getHeight(null); // ???? if (0 == newWidth || 0 == newHeight) { newWidth = srcImageWidth; newHeight = srcImageHeight; } BufferedImage distImage = new BufferedImage(newWidth, newHeight, bufferedImageType); // Graphics2D graphics2d = distImage.createGraphics(); graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics2d.drawImage(srcImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0, null); // ??(?) mergeable.draw(graphics2d); // ??(?) if (null != mergeables && mergeables.length > 0) { for (Mergeable d : mergeables) { d.draw(graphics2d); } } // ? ImageIO.write(distImage, destType.name(), outputStream); } catch (IOException e) { LOG.error("method:mergeResource,destType:" + destType + ",newHeight:" + newHeight + ",newWidth:" + newWidth + ",errorMsg:" + e.getMessage(), e); throw new HumanNeededError(Error.IO_ERROR); } }