java-2d

How do i align this text correctly?

浪子不回头ぞ 提交于 2019-11-27 02:07:10
I wrote this polar clock today and i am almost finished exept i want to align my text inside the line similar to this . Does anyone know how to do this? Ive tried to use FontRenderContext and font metrics but i cant seem to get it to work. Here is the whole source code so you can compile it and see for yourselves. import java.applet.Applet; import java.awt.AWTEvent; import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.Shape; import java.awt.Toolkit; import java.awt.font

How to draw a transparent shape using a Graphics object g?

耗尽温柔 提交于 2019-11-26 23:25:30
问题 I want to create a “ring” in a BufferedImage with a transparent background. I can draw the circle with a transparent background like this: BufferedImage bi = new BufferedImage(d, d, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) bi.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(c); g.fillOval(0, 0, d, d); But now I want to draw a smaller transparent circle in the middle of it to make a ring (so when I draw this

setOpaque(true/false); Java

◇◆丶佛笑我妖孽 提交于 2019-11-26 23:06:10
In Java2D when you use setOpaque I am a little confused on what the true and false does. For example I know that in Swing Opaque means that when painting Swing wont paint what is behind the component. Or is this backwards? Which one is it? Thanks Lawrence Dol The short answer to your question is that "opaque" is defined in English as completely non-transparent. Therefore an opaque component is one which paints it's entire rectangle, and every pixel is not at all translucent to any degree. However, the Swing component opacity API is one of those mis-designed and therefore often mis-used APIs.

Java 2D Drawing Optimal Performance

核能气质少年 提交于 2019-11-26 22:32:53
问题 I'm in the process of writing a Java 2D game. I'm using the built-in Java 2D drawing libraries, drawing on a Graphics2D I acquire from a BufferStrategy from a Canvas in a JFrame (which is sometimes full-screened). The BufferStrategy is double-buffered. Repainting is done actively, via a timer. I'm having some performance issues though, especially on Linux. And Java2D has so very many ways of creating graphics buffers and drawing graphics that I just don't know if I'm doing the right thing. I

Drawing a Component to BufferedImage causes display corruption

时光毁灭记忆、已成空白 提交于 2019-11-26 19:11:41
I am using the JScrollNavigator component described here , in order to provide a navigation window onto a large "canvas-like" CAD component I have embedded within a JScrollPane . I have tried to adapt the JScrollNavigator to draw a thumbnail image of the canvas to provide some additional context to the user. However, the action of doing this causes the rendering of my application's main frame to become corrupted. Specifically, it is the action of calling paint(Graphics) on the viewport component (i.e. my main canvas), passing in the Graphics object created by the BufferedImage that causes

java buffered image created with red mask

天大地大妈咪最大 提交于 2019-11-26 18:35:30
问题 I am having trouble reading an image. If I do the following URL url = new URL("http://tctechcrunch2011.files.wordpress.com/2012/10/gmm.jpg"); ImageInputStream stream = ImageIO.createImageInputStream(url.openStream()); ImageReader reader = ImageIO.getImageReaders(stream).next(); reader.setInput(stream, true, true); BufferedImage image = reader.read(0); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ImageWriter writer = ImageIO.getImageWritersByFormatName("JPEG").next();

Line2D decoration tips needed - Graphics2D

谁说胖子不能爱 提交于 2019-11-26 18:35:05
问题 I have Line2D and Arc2D objects laid out on my JPanel by Graphics2D drawing. You can have a look a part of it on this question " How to make pixel perfect Line2D in - Graphics2D ". Now what I want to achieve is, I want to create two parallel lines and arcs for all Line2D and Arc2D objects. Visually, Normal Line2D and Arc2D drawn currently, Want to decorate it like this, My Thoughts so far, I might be able to achieve this by creating two different line and give an offset +gap and -gap from my

Java2D: Is it always safe to cast Graphics into Graphics2D

六月ゝ 毕业季﹏ 提交于 2019-11-26 16:48:45
问题 Assuming we always use a Sun JVM (say, 1.5+), is it always safe to cast a Graphics reference to Graphics2D? I haven't seen it cause any problems yet and, to my understanding, the Graphics class is legacy code but the Java designers didn't want to change the interfaces for Swing and AWT classes in order to preserver backwards compatibility. 回答1: According to the discussion here, it is always safe to cast from Graphics to Graphics2D . However I am not able to quickly find the official Sun

How to resize text in java

*爱你&永不变心* 提交于 2019-11-26 16:45:46
I have seen that in photoshop text can be easily resized just by dragging them. How can we do the same thing in Java? Any idea on how to resize text in java? Added a snapshot of letter "A" resized in photoshop Please let me know what is wrong with this code? public class ResizeImage extends JFrame { public ResizeImage(){ JPanel panel = new JPanel(){ public void paintComponent(Graphics g) { // In your paint(Graphics g) method // Create a buffered image for use as text layer BufferedImage textLayer = new BufferedImage(240, 240, BufferedImage.TYPE_INT_RGB); // Get the graphics instance of the

Is there a 100% Java alternative to ImageIO for reading JPEG files?

自闭症网瘾萝莉.ら 提交于 2019-11-26 15:47:32
问题 We are using Java2D to resize photos uploaded to our website, but we run into an issue (a seemingly old one, cf.: http://forums.sun.com/thread.jspa?threadID=5425569) - a few particular JPEGs raise a CMMException when we try to ImageIO.read() an InputStream containing their binary data: java.awt.color.CMMException: Invalid image format at sun.awt.color.CMM.checkStatus(CMM.java:131) at sun.awt.color.ICC_Transform.<init>(ICC_Transform.java:89) at java.awt.image.ColorConvertOp.filter