java-2d

Algorithm to create an image of an elliptical brush?

I need to be able to accept elliptical(computed) brush parameters such as spacing, hardness, roundness, angle and diameter and then compute a bitmap image based on those attributes. Does anyone know the algorithm(or where I can find it) to do this? I have limited experience in graphics programming and I have been unable to find it so f...

setOpaque(true/false); Java

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 ...

Best approach to storing image pixels in bottom-up order in Java

I have an array of bytes representing an image in Windows BMP format and I would like my library to present it to the Java application as a BufferedImage, without copying the pixel data. The main problem is that all implementations of Raster in the JDK store image pixels in top-down, left-to-right order whereas BMP pixel data is stored ...

JPanel Layout Image Cutoff

I am adding images to a JPanel but the images are getting cut off. I was originally trying BorderLayout but that only worked for one image and adding others added image cut-off. So I switched to other layouts and the best and closest I could get was BoxLayout however that adds a very large cut-off which is not acceptable either. So basi...

JLabel animation in JPanel

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 t...

Need help understanding the affect of two java gui-related system properties

Hello, I had a problem envolving a mixing of lightweight and heavyweight components in java. http://stackoverflow.com/questions/2463108/weird-swing-heavyweight-lightweight-mixing-problem/2468519#2468519 A solution that was suggested to me (outside stackoverflow) was to set the system properties sun.awt.noerasebackground and sun.java2d...

Java: Line appears when using AffineTransform to scale image

Hi, I'm having a problem with image scaling. When I use the following code to scale an image it ends up with a line either at the bottom or on the right side of the image. double scale = 1; if (scaleHeight >= scaleWidth) { scale = scaleWidth; } else { scale = scaleHeight; } AffineTransform af = new AffineTransform(); af.scale(s...

Collision Detection - Java - Rectangle

I would like to know if this is a good idea that conforms to best practices that does not lead to obscenely confusing code or major performance hit(s): Make my own Collision detection class that extends Rectangle class. Then when instantiating that object doing something such as Collision col = new Rectangle(); <- Should I do that or i...

How can I draw the control points of a Bézier Path in Java?

I have created a Path of Bézier curves and it works fine to draw the path. But I don't know How I can draw the Control Points together with the Path. Is that possible or do I have to keep track of them in another datastructure? Update: The reason to why I want to draw the control points, is that I will let the user to edit the curves us...

How to calculate the length of a Path2D in Java?

I have some paths represented by Path2D. The Path consist of multiple CubicCurve2D or Line2D segments that are connected to each other. I would like to calculate or get the length from the start to the end of a Path. How can I calculate it or get it? Is it possible? I have checked the API documentation, but couldn't find any useful metho...

How can I draw on JPanel using another quadrant for the coordinates?

I would like to draw some shapes on a JPanel by overriding paintComponent. I would like to be able to pan and zoom. Panning and zooming is easy to do with AffineTransform and the setTransform method on the Graphics2D object. After doing that I can easyli draw the shapes with g2.draw(myShape) The shapes are defined with the "world coordin...

Move multiple BufferedImage in Java2D?

How can I mousedrag different BufferedImages in Java2D? For instance, if I have ten or more images, how can I move that images which my mouse is over? Now I'm importing an BufferedImage with BufferedImage img = new BufferdImage(new File("filename")); And I'm painting this with Graphics2D with public void paintComponent(Graphics g) ...

Rendering text in an image in Java

Are there any nice libraries to render text in an image for Java? Java has a 2d text library, http://java.sun.com/docs/books/tutorial/2d/text/index.html but not sure if theres a better library to use. ...

Java2D text get polygons for custom rendering!

Hi, can anybody provide me with an example of how to get the java 2D shape polygons of a textLayout so I can modify them for custom rendering? I am not experienced with Java and have a hard time crawling through the reference so some input would be great! Thanks! ...

Manipulating PNGs in Java

Is there an easy way to manipulate PNGs in Java? I know I can read into a BufferedImage and write that back out, but I need to add clear pixels around the edge of an image. Is there an easy way to do this? ...

Measuring time spent in application / thread

I am writing a simulation in Java whereby objects act under Newtonian physics. An object may have a force applied to it and the resulting velocity causes it to move across the screen. The nature of the simulation means that objects move in discrete steps depending on the time ellapsed between the current and previous iteration of the a...

How to display many SVGs in Java with high performance

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 dra...

Get object location Java2D (not corner).

How do I get JLabel location instead of top left x/y location of the object in Java? ...

Java2D Distance Collision Detection

My current setup is only useful once collision has been made; obviously there has to be something better than this? public boolean CollisionCheck(Rectangle rect1, Rectangle rect2) { if(rect1.intersects(rect2)) { return true; } return false; } How can I do preemptive collision detection? ...

Java: Friendlier way to get an instance of FontMetrics

Hi people, Is there a friendlier way to get an instance of FontMetrics than FontMetrics fm = Graphics.getFontMetrics(Font); I hate this way because of the following example: If you want to create in a game a menu and you want all the menuitems in the center of the screen you need fontmetrics. But, mostly, menuitems are clickable. So...