java-2d

Java create anaglyph (red/blue image)

I'm writing a Java game engine (http://victoryengine.org) and I've been experimenting with generating "3d" images with depth that you can see with those red/blue glasses. I'm using Java2D for graphics. I've created something that works, but is very slow (by manually copying pixel values and stuff like that). What I need to is take two ...

How to make a curve to join two objects editable?

Hi, I'm involved in a project in which we're doing a visual editor (written in Java). Now, I'm trying to make curves that join two different objects that I'm painting in a class that extends JPanel (this class is what I'm using to paint, inside a JFrame, overriding the method paintComponent). I'm in troubles because I'm using the class Q...

How to draw a curve that passes through three points?

Hi, I'm trying to create a curve that passes through three given points in Java (I'm drawing the curves through a class that extends JPanel). How can I make it? Thanks! ...

Write text along a curve in Java.

I was wondering if it were possible to fit text along the curve of a circle. It would be great if there were a way to accomplish this in Java2D. ...

How to determine the pixel size of text using Groovy's GraphicsBuilder module?

If I am drawing images using Groovy's GraphicsBuilder, how do I determine the size of the text I am drawing? I could use Java's FontMetrics class but it requires a Graphics object and I'm not sure how to obtain one when using GraphicsBuilder. ...

Inside clipping with Java Graphics

I need to draw a line using java.awt.Graphis, but only the portion of the line that lies outside a rectangle should be rendered. Is it possible to use the Graphics clipping support? Or do I need to calculate the intersection and clip the line myself? ...

[Java2D] Resize problems

Hi gentlemens (and ladys) I am currently creating an Eclipse View that has to contribute an Eclipse RCP app' and which must be nice (and only this one, I don't need an eclipse skin or something like that because my eclipse RCP app must look the same as a regular eclipse app), I must integrate translucent png, mouving gradients and contr...

How to disable the default painting behaviour of wheel scroll event on JScroolPane

I recently purchased the book Filthy Rich Clients and i found it really useful and fun. Building on one example from the book i tried implementing a custom ScrollPane that displays a "shadow" on the bottom of its view over the component to be displayed. I ended up with the code below. It works but not perfectly. Specifically when i scrol...

Do I need to use OpenGL in my 2D Java sim game?

Hi all. I have recently been developing a sim game in java, as many of my questions show, and it's come a long way! Graphically, it is somewhat lacking, and at current I'm using shapes for items, people, rooms ect. I was looking at other similar projects, and noticed that one was using OpenGL. I have been reading CokeAndCode "space inva...

Combined re-scaling and color reduction of an image in Java?

Given a rectangular input image I'd like to create an output image of size 40x40 pixels using a maximum of 10 colors. Hence, the two operatons needed are re-scaling and color reduction. The following ImageMagick command does the trick: convert input.png -scale 40x40 -colors 10 output.png How would you achieve the corresponding result...

Lift image upload, resize, store in database, display

Is there a succinct example of how to upload an image, resize it, store it in a database and then serve the image up using Lift? I'm sure I could piece it together from the file upload, Java 2D API, Lift Mapper and Response APIs. But is there any example code I can follow to do it the 'correct' or recommended way? ...

Paint component doesn't print polygon according to intended coordinate

I have problem drawing the triangle polygons based on the coordinates which are stored in linked list. When I checked the linked list elements using System.out.println in paint component method Public void paintComponent (Graphics g) { ... for (Polygon p : triangles) { g2.drawPolygon(triangle); ... // print the elements...

Scala 2D Animation library

Can anyone recommend a good 2D animation package for Scala? I prefer something which already have some basic events handling, more like JavaFX than like processing.org. ...

What is the best way to call repaint() at regular intervals in my Java2D program?

I'm looking to call repaint() in my Java2D simulator at regular intervals. What would be the best way to do this? Should I start another thread and have a loop that keeps track of currentTimeMillis()? Or is there a better way? ...

How do I do double buffering in Java2D?

I'm drawing a bunch of primitives using Java2D on the screen and I'm getting a lot of tearing/flicker. How can I enable/use double-buffering so it draws it off screen then shows the whole thing? ...

How can I draw a portion of my Java2D simulation that doesn't change to an image/buffer so I don't have to redraw it's primitives each time?

How can I draw a portion of my Java2D simulation that doesn't change to an image/buffer so I don't have to redraw it's primitives each time? I have a portion of my Java2D simulation that requires me to draw thousands of small lines. However, this portion of the app doesn't change once drawn so it doesn't make sense to re-draw thousands...

Java help. How to draw images

Hi I'm starting to work on this project where I need to have a picture (map of the US) and then I need to circles of different sizes on the map at different locations. Something like this: http://www.npr.org/templates/story/story.php?storyId=110997398 What's the best way to go about doing it? I've never dealt with Java 2-d but I'm guess...

How to draw circle on JPanel? Java 2D

I have a JPanel for which I set some image as the background. I need to draw a bunch of circles on top of the image. Now the circles will be positioned based on some coordinate x,y, and the size will be based on some integer size. This is what I have as my class. import java.awt.Dimension; import java.awt.Graphics; import java.awt.Imag...

Java 2D. Hovering over Circle

If I draw some circles using Java2D. Is there a way display some text when I hover over any of the circles? i.e. I want to display the ID of that circle and some other stuff. ...

Java VolatileImage - validate() vs contentsLost()

When using VolatileImage to do accerlerated Java2D operations, how do you properly use the methods validate(GraphicsConfiguration) and contentsLost() to ensure that nothing goes wrong. When do you call which method? ...