java-2d

Can't draw thin lines with Java2D

蹲街弑〆低调 提交于 2019-12-06 03:26:17
问题 I'm trying to draw a polygon with a stroke of 1 pixel. Because the entire polygon is scaled by 100, I set the line width to 0.01. For some reason though, the polygon gets drawn with an on-screen line width of what looks to be 100 pixels instead of 1. I'm using GeneralPath as the polygon shape. Thin lines do get drawn if I use the same approach for drawing Line2D shapes. g2d.scale(100, 100); g2d.setStroke(new BasicStroke(0.01f)); g2d.draw(theShape); New info: If I remove the setStroke line I

How to display many SVGs in Java with high performance

烈酒焚心 提交于 2019-12-06 02:39:33
What I want My goal is to be able to display a large number of SVG images on a single drawing area in Java, each with its own translation/rotation/scale values. I'm looking for the simplest solution allowing this, optionally even using OpenGL to speed things up. What I've Tried My initial naive approach was to use SVGSalamander to draw directly on a JPanel, but the performance was pathetic. I poked around around and learned that I should do something like manually convert each SVG into a BufferedImage created with createCompatibleImage, then do the transformations I want, then draw it using

Java Swing deprecated in favor of JavaFx 2.0 [closed]

◇◆丶佛笑我妖孽 提交于 2019-12-06 00:00:38
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Am I correct that Oracle has deprecated Swing and that JavaFx 2.0 is it's official replacement? This makes sense to me because it

Java Swing based game framework. Any advice? [closed]

南笙酒味 提交于 2019-12-05 23:39:29
I'm developing game using Java Swing framework. Does anyone know good framework based on Swing? Mostly I care about performance of redrawing. Swing is fine for simple games, but if you really care about performance of redrawing, you should probably take a look at one of the frameworks based on OpenGL. Examples: http://www.lwjgl.org/ - quite a low level library but very fast. basically raw OpenGL. http://www.slick2d.org/ - a popular and fairly easy to use 2D game library. http://jmonkeyengine.com/ - a good choice if you want a full 3D engine. In particular, if you want to do more complex

Java GUI Rotation and Translation of Rectangle

泪湿孤枕 提交于 2019-12-05 16:57:37
I am trying to draw a rectangle in JPanel that would translate and then rotate itself to mimic the movement of a car. I have been able to make the rectangle translate and rotate, however it rotates around the origin of (0,0). I'm very pleased that I was able to have the rectangle move and rotate as I am very new to Java GUI, but I can not seem to get how to have the rectangle rotate around itself, because I experimented more with it, and when I initialized the rectangle and rotate it 45 degrees it's position was changed, which I would assume is the transform matrix that is appended from the

Find the intersection(s) of a pair of QuadCurve2Ds

早过忘川 提交于 2019-12-05 11:52:52
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 code: QuadCurve2D curve1 = new QuadCurve2D.Double(-2.00, -2.00, +0.75, +4.75, +2.00, -0.75);

How do you draw shapes on a JPanel, which is within another JPanel?

寵の児 提交于 2019-12-05 07:12:48
问题 I'm currently trying to draw shapes on a JPanel , which is within another JPanel , within a JFrame . I've searched Google and Youtube and found out how to draw shapes within a JFrame that has one panel, but have found nothing which can help me with what I'm doing. (maybe I'm not seeing something). Code I've seen so far: public class GameScreen { public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.red); g.drawRect(100, 10, 30, 40); } public static void main

AffineTransform without transforming Stroke?

大兔子大兔子 提交于 2019-12-05 01:35:56
When using the Graphics2D scale() function with two different parameters (scaling by different ratios in x- and y-direction), everything drawn later on this Graphics2D object is scaled too. This has the strange effect that lines drawn in one direction are thicker than those in another direction. The following program produces this effect, it shows this window: public class StrokeExample extends JPanel { public void paintComponent(Graphics context) { super.paintComponent(context); Graphics2D g = (Graphics2D)context.create(); g.setStroke(new BasicStroke(0.2f)); int height = getHeight(); int

JLabel animation in JPanel

纵饮孤独 提交于 2019-12-04 19:28:41
After scratching around I found that it's best to implement a custom image component by extending a JLabel. So far that has worked great as I can add multiple "images" (jlabels without the layout breaking. I just have a question that I hope someone can answer for me. I noticed that in order to animate JLabels across the screen I need to setlayout(null); and setbounds of the component and then to animate eventually setlocation(x,y); . Is this a best practice or a terrible way to animate a component? I plan on eventually making an animation class but I don't want to do so and end up having to

Scala library for image creation

落花浮王杯 提交于 2019-12-04 14:53:58
Is there any good Scala or Java library for image manipulation? For simple tasks like composing an image with some others then generating a thumb? they're all a bit old school, and maybe inconvenient, but java.awt, java.awt.image, and javax.imageio has everything you need to blend and rescale images. You can find some blending example code e.g. here http://www.curious-creature.org/2006/09/20/new-blendings-modes-for-java2d/ you can find some examples of rescaling and generating image bytes e.g. here https://sourceforge.net/projects/ssim/?source=directory there are probably newer/easier