java-2d

Draw ring with given thickness, position, and radius. (Java2D)

帅比萌擦擦* 提交于 2019-12-08 03:07:25
I need to draw a ring, with given thickness, that looks something like this: The center must be transparent, so that it doesn't cover previously drawn shapes. (or other rings) I've tried something like this: //g is a Graphics2D object g.setColor(Color.RED); g.drawOval(x,y,width,height); g.setColor(Color.WHITE); g.drawOval(x+thickness,y+thickness,width-2*thickness,height-2*thickness); which draws a satisfactory ring, but it covers other shapes; the interior is white, not transparent. How can I modify/rewrite my code so that it doesn't do that? You can create an Area from an Ellipse2D that

Repaint() and double-buffering in java8, bug?

帅比萌擦擦* 提交于 2019-12-07 21:46:47
问题 I've been playing with animation in Swing on Java 8 and have encountered some strange behaviour: sometimes content of a component suddenly becomes stale after calling repaint() on some other unrelated component. Below is the code, which reproduces this behaviour for me: import javax.swing.*; import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; public class Crosshair extends JPanel { private int currentMouseX = 0; private int currentMouseY = 0; public

How to draw absolutely custom shape in Java?

只愿长相守 提交于 2019-12-07 18:23:50
问题 The most complex shape, supported by Java2D API is a Bezier segment. Suppose I want to draw rational segment (each control point has a weight and the entire rendering formula is slightly different). How to accomplish that? Is it possible to extend rendering engine to be able to draw more complex shapes? UPDATE Usual way to implement custom shape is implementing Shape interface. This interface has key methods to return PathIterator while PathIterator iterates over segment types. There are only

Find the intersection(s) of a pair of QuadCurve2Ds

江枫思渺然 提交于 2019-12-07 08:16:59
问题 Is there an easy way to approximate the points (if any) where two instances of QuadCurve2D intersect? That is, how could I compute the coordinates of the red dots in this diagram? There is no obvious method in QuadCurve2D to do this. (note: the points are not exact as I have tweaked them manually for the diagram. Also note the "missing" fourth point which does not lie on the curve segment even though it lies on the (infinite) parabola.) These two curve segments were created with the following

Fastest way to compare pixel values between two BufferedImages?

梦想与她 提交于 2019-12-07 03:22:33
问题 I have a BufferedImage of type TYPE_INT_BGR. I need to do a pixel-by-pixel comparison to another BufferedImage to compute the "distance" between the two images. I have something that works, but is slow. I get a pixel from the "reference" image, break it up into RGB bytes with: int pixel = referenceImage.getRGB(col, row); int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = (pixel) & 0xff; I compare the r/g/b values to the corresponding pixel of the candidate image, and

Repaint() and double-buffering in java8, bug?

偶尔善良 提交于 2019-12-06 13:26:34
I've been playing with animation in Swing on Java 8 and have encountered some strange behaviour: sometimes content of a component suddenly becomes stale after calling repaint() on some other unrelated component. Below is the code, which reproduces this behaviour for me: import javax.swing.*; import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; public class Crosshair extends JPanel { private int currentMouseX = 0; private int currentMouseY = 0; public Crosshair() { addMouseMotionListener(new MouseAdapter() { @Override public void mouseMoved(MouseEvent e) {

Collision detection tutorials [closed]

戏子无情 提交于 2019-12-06 11:45:25
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I'm supposed to develop a Java game using AWT. I'm stuck with the concept of "collision detection". If you can help me with any tutorials that explain the concept (how it works) or give examples (source code), I'd be grateful. ins0m A strong tutorial on 2d collision detection can be found at metanetsoftware (makes of N) The authors write about the theoretical fundamentals and the challenges. They give you some

How to get absolute coordinates after transformation

懵懂的女人 提交于 2019-12-06 08:09:49
I am drawing Java 2D stuff like this: g2.translate( getWidth() / 2, getHeight() / 2 ); g2.rotate( angle ); g2.draw( new Ellipse2D.Double( -1, -1, 1, 1 ) ); Now I want to kow the coordinates of the ellipse on my sceen. Any idea how to get it? So I need the conversion from logical to physical space. Get the AffineTransform from the Graphics2D object and use the transform(src, dst) method to go to screen coordinates (you can do this for any point). If you want the path of the ellipse you can use Ellipse2D.getPathIterator(AffineTransform at) - it returns a PathIterator . This example gets the

How to draw a Round rectangle in java with normal rectangle outline

匆匆过客 提交于 2019-12-06 05:12:15
问题 For my java application i need a Round rectangle with an outline that looks like a normal rectangle, like this I know you can do that by drawing a normal rectangle and a RoundRect inside it but i don't want to draw a RoundRect inside it because I want to draw something else in it. So a round rect with normal corners. How do I draw that in Java? The problem is that the rectangle looks like this if I use layers: The corners are filled up with the wrong color. How do I prevent that? 回答1: I can

Java2D: BufferedImage not accelerated on Ubuntu

半世苍凉 提交于 2019-12-06 04:39:10
问题 We are currently developing a game in Java using the Java2D API and are experiencing some strange performance issues when running it in an Ubuntu environment. Our frame rate drops from an average of 62fps on Windows and Mac systems to about 10fps on Ubuntu. After some hours of debugging and testing various JVM flags it seems to be that BufferedImages using a bitmask are not being accelerated under Ubuntu because System.out.println(img.getCapabilities(config).isAccelerated()); prints out false