Questions tagged [java-2d]

Java 2D is an API for drawing two-dimensional graphics using the Java programming language.

1076 questions
89
votes
2 answers

Java2D: Increase the line width

I want to increase the Line2D width. I could not find any method to do that. Do I need to actually make a small rectangle for this purpose?
Boolean
  • 14,266
  • 30
  • 88
  • 129
61
votes
2 answers

Setting LCD gamma / contrast (IntelliJ IDEA, JDK 8)

I am having trouble with anti-aliased text in IntelliJ IDEA. That thing for some reason ships with its own version of OpenJDK 8. Anyway... sub-pixel aliasing is acceptable with dark-on-bright text: But the gamma is wrong for bright-on-dark…
0__
  • 66,707
  • 21
  • 171
  • 266
59
votes
3 answers

Java2D Performance Issues

I'm having performance oddities with Java2D. I know of the sun.java2d.opengl VM parameter to enable 3D acceleration for 2D, but even using that has some weird issues. Here are results of tests I ran: Drawing a 25x18 map with 32x32 pixel tiles on a…
Consty
  • 1,792
  • 1
  • 15
  • 14
38
votes
3 answers

Java2D: Is it always safe to cast Graphics into Graphics2D

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…
Tim Frey
  • 9,901
  • 9
  • 44
  • 60
33
votes
9 answers

Java 2D Drawing Optimal Performance

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…
Zarkonnen
  • 22,200
  • 14
  • 65
  • 81
28
votes
7 answers

How to draw a directed arrow line in Java?

I want to draw a directed arrow line through Java. At present, I am using java.awt.Line2D.Double class to draw a line g2.setStroke(new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g2 is an instance of Graphics2D g2.draw(new…
Amit
  • 33,847
  • 91
  • 226
  • 299
27
votes
17 answers

Occasional InterruptedException when quitting a Swing application

I recently updated my computer to a more powerful one, with a quad-core hyperthreading processor (i7), thus plenty of real concurrency available. Now I'm occasionally getting the following error when quitting (System.exit(0)) an application (with a…
Joonas Pulakka
  • 36,252
  • 29
  • 106
  • 169
25
votes
9 answers

How to draw a circle with given X and Y coordinates as the middle spot of the circle?

I have developed a telecommunication application for locating signal strengths from the towers. I have used java swing and I'm having a problem when drawing the circle around the given point of the mobile signal transmitter tower location. I have…
нαƒєєz
  • 1,239
  • 4
  • 17
  • 27
25
votes
1 answer

Collision detection with complex shapes

I am wanting to make a game that has each level loaded from an image. I want to draw up the whole level in Photoshop, and then set it as the background and allow the player to walk over it. I want another invisible image to go over top which will be…
calebmanley
  • 421
  • 1
  • 5
  • 16
21
votes
6 answers

Game design in an OO manner

I'm designing a simple game, which uses Java 2D and Newtonian physics. Currently my main "game loop" looks something like: do { for (GameEntity entity : entities) { entity.update(gameContext); } for (Drawable drawable : drawables) { …
Adamski
  • 54,009
  • 15
  • 113
  • 152
20
votes
2 answers

How can I create a drop shadow, inner glow and outer glow in Java Swing?

I am generating some images using the Graphics2D interface, and occasionally I'd like to be able to draw some text on the image and apply to it effects like the ones in Adobe Photoshop. Right now to generate a 'shadow' on the text I am drawing the…
Tom Neyland
  • 6,860
  • 2
  • 36
  • 52
20
votes
3 answers

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

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…
chesterbr
  • 2,940
  • 3
  • 29
  • 26
19
votes
5 answers

How to get a good quality thumbnail

I am trying to create a high quality thumbnail of this image, with Java and Scalr 3.2 This is the relevant source code, where THUMB_WIDTH = 77 and THUMB_HEIGHT = 57 BufferedImage srcImg = ImageIO.read(new File(sourceFile)); BufferedImage dstImg =…
stivlo
  • 83,644
  • 31
  • 142
  • 199
17
votes
4 answers

What are some faster alternatives to Java2d?

I'm looking to do some physics simulations and I need fast rendering in Java. I've run into performance issues with Java2d in the past, so what are the fast alternatives? Is JOGL significantly faster than Java2d?
KingNestor
  • 65,976
  • 51
  • 121
  • 152
14
votes
3 answers

Smoothing a jagged path

I was participating in the thread Image/Graphic into a Shape the other day and made a hackish attempt to get the outline of an image by adding a Rectangle iteratively to an Area. That was very slow. This example instead builds a GeneralPath and…
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
1
2 3
71 72