java-2d

[Java2D] Is this bad practice? Multiple Graphics2D Objects

I've created a JPanel canvas that holds all graphics; namely JLabel. To get animated sprites to work you have to over ride the paintComponent of the extended JLabel class. I've successfully implemented animated sprites this way. Is it bad practice to have a Graphics2D canvas and then have multiple 'images' in their own Graphics2D? ...

Faster: SWT or Java2D?

Which has faster graphics performance: SWT or Java2D? On MacOSX, Does SWT's graphics go through Quartz Extreme which in turn is rendered using hardware-accelerated OpenGL? I'm not referring to the native UI controls but asking about custom 2D graphics rendering like text, lines, curves and polygons. ...

(Java) How can I create a Drop Shadow/Inner Glow/Outer Glow similar to Photoshop.

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 text twice, once in the original color, and once in black with a slight (1px) x&y offset....

How can I improve Java2D performance of TextLayout.draw(..)

I'm using the Java2D TextLayout class together with a LineBreakMeasurer and an AttributedCharacterIterator to draw a piece of text into a box. The text is wrapped. Profiling shows me that the code is very slow. Most of the time is lost in the method TextLayout.draw(..). Does anyone have a suggestion for speed improvement? // Get i...

non-destructive transformations on java2d objects

I would like to be able to zoom and unzoom on a Java2D scene made of Path2D.Double without thickening the lines, just by dilating the distances. I'v tried to apply a transformation to the Graphics2D object the paintComponent method receives, but this makes the lines thicker. The only way I found was to apply a transformation to the lin...

MVC pattern and Java2D

hi i want implement my Java2D application with MVC pattern.i have some classes that have paint() method [my shapes] and a class that extends Canvas [java.awt.Canvas] class and JFrame class.i add Canvas class to JFrame and put a button on JFrame.when user click on button must Button's Action class make object from shape and draw on C...

java2d and draw many shapes

hi in my Java2D Application,i have some Buttons that draw shapes but when i pressed one button paint method of correspond shape cause my draw panel [JPanel or Canvas] is clear.i need all shapes stay in Draw panel.please give me idea for solve this. thanks ...

Java BufferedImage padding.

Is there any faster way to achieve padding of pixels to a BufferedImage than drawing it centered on larger BufferedImage? ...

Drawing Java 2D Charts span across multiple views or panels or horizontal-scrolling

Hi I'm drawing a graph using Java 2d graphics (i.e. drawing and filling rectangles) straightaway on a JFrame from a set of values stored in an Arraylist. But when the ArrayList has very large number of values (can even go upto 3500 in size), the drawing is compressed - where the graph seems less informative and even the labels on the X...

Render 2 images with the top image background color transparent

I'm programming in java. I am essentially doing a paint like tool. The user can select a background image, use a mouse to draw a line, or erase a line. When erasing a line the background image should still the same. So what I was trying to do was have a separate image for the background image and another image to track the mouse moveme...

How to create a big image file from many tiles in java ?

My program produces 10 x 10 tiles images of 3000x3000 pixel, one by one (currently saved to 100 files named image_x_y.jpg) I want to assemble these 100 images into one big image, without loading everything in memory. My goal is to create one big image file, of 30'000 * 30'000 pixels. I'm looking for a way to do this without using JAI (...

BufferedImage imageType in swing

I'm writing a widget that does some caching to avoid unecessary calls to Shape.draw on a bunch of shapes at every repaint. I've tried to do something like this (scala code): private val buffer = new BufferedImage(width, height, /* (1) */) ... override def paintComponent(Graphics2D g) = { if (hasChanged) { val bg = buffer.getGrap...

How to set different strokes on a Java 2D GeneralPath?

I want to draw a math symbol with GeneralPath. GeneralPath gp1 = new GeneralPath(); gp1.moveTo( 50, 10 ); gp1.lineTo( 50, 80 ); gp1.closePath(); Now I want to draw one line thicker that the other and the connection should look nice. Lets take the < for example where I want the upper line / four times thicker the \ line. If I draw the ...

how to use setRGB() after modifying pixels? Do I need to use Hexadecimal?

For my project, I have to read each pixel in an image, perform a math operation on each pixel, then display the results of the modified pixel in an updated image. For this example, I took the square root of each pixel. public void rootCalc(){//go through the rows and columns for(int x=grayscale_orig.getWidth()...

simple text wrapping and copyfitting language/library

I'm writing a flashcard generating library. The user provides a text file, my program needs to output something that can be printed, directly or indirectly (e.g., TeX, PS, PDF, XSL-FO). My text formatting is very simple: plain, monospace, italic, or bold. I also need a way to center text in the region. Nothing else. However, I need some...

is it better/faster to paint an image as the background of a button or use the Java2D to paint it

Say I have a button and want to change the background button to a gradient, is it better/faster to draw a gradient using Java2D or just get an image with that gradient and put it in the background of the button? ...

java2d and scale

hi when I scale my shape [Rectangle] with g2d.scale(2,2) or with AffineTransform , I can't detect correct hit on shape because my shape scale still same as previous and only view of shape is change. I need solution for solving this problem [change size of shape after Transform]. thanks ...

Suitable platform for a 2D simulator using java

Hi, I have to do my final year project and I'm planning to use a visual simulator to simulate it. So I have to create a basic simulator and the program would be run in java. But I have a problem as to what to use to create the simulator. Should I use jmonkey or java2D or java 3D. What I would want is a basic 2d simulator. Please help me...

draw image or draw filled circle?

We have an old Java Swing application. we need to display thousands, hundreds of thousands small circle spots on the canvas based on the real data. Right now we have an image file of a small circle spot. When we need it, we draw that image onto the canvas, thousands, hundreds of thousands times. Now I am think it may be better (better p...

How to effectively render video in Java (AWT??)

Hi, in my project I've got a class FrameProducer firing events each time a video frame has been created. Each frame is an image returned as an java.awt.Image.BufferedImage object. I've got 2 FrameProducer objects and would like to render BufferedImage's produced by them simultaneously on the screen. I would like the picture rendered on...