Questions tagged [java-2d]

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

1076 questions
9
votes
3 answers

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…
Joe
  • 46,419
  • 33
  • 155
  • 245
9
votes
3 answers

Implementing Polygon2D in Java 2D

I'm creating a 2D game in Java using the Java2D library for drawing, and I really need a float-precision Polygon object that I can use both to draw game objects and to do collision detection on them. Unfortunately, Java's Polygon object comes in int…
Edward
  • 5,942
  • 4
  • 38
  • 55
8
votes
4 answers

Java2D: scaling issues

I'm a reasonably experienced Java programmer but relatively new to Java2D. I'm trying to scale an image but I'm getting poor quality results. The image is a preview of a panel so contains things like text and textfields. I'll always be scaling down,…
Johnathan
  • 318
  • 4
  • 8
8
votes
1 answer

Drawing smoke effects with java

Is there any way to draw a smoke effect in java (by using Java2D API). I want to achieve this: when a user provides the color for the smoke, the program automatically draws a smoke effect with that color. How could I do this?
Mad
  • 81
  • 1
  • 2
8
votes
1 answer

Drawing the Cannabis Curve

Inspired by Cannabis Equation from the Math site (it refers to the Wolfram Research Cannabis Curve) I was wondering.. How would we draw this curve using Java-2D?
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
7
votes
2 answers

java drawing a circle when mouse clicked

i am writing a program that when the mouse is clicked, a circle will be drawn. The below code i've wrote so far. import java.awt.*; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import…
hkguile
  • 4,235
  • 17
  • 68
  • 139
7
votes
2 answers

PNG - Is it possible to reduce the palette using Java 2D?

If I have a PNG image opened as a BufferedImage, is it possible to reduce the palette in the PNG image so that there is less colour (less bits per pixel / colour depth)? For example, if you look at Colour depth in Wikipedia, I would like to use 16…
Joeblackdev
  • 7,217
  • 24
  • 69
  • 106
7
votes
2 answers

Java game 2D overlapping shadows with Swing

I am currently developing a 2D Java game using Swing as my primary drawing component. Every object has a shadow (BufferedImage) but every shadow overlaps other shadows. Is it possible to only have the shadows not overlap each other? Because I still…
7
votes
3 answers

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…
Laurent K
  • 3,503
  • 3
  • 30
  • 36
7
votes
5 answers

Java- how to clear graphics from a JPanel

I'm creating a simple program where I draw a black oval where I click with my mouse. However I want a new oval to appear and the old one to disappear. How would I go about doing this? I've messed around with the removeAll() method inserted into my…
anonymous noob
  • 145
  • 2
  • 3
  • 12
7
votes
1 answer

Icon with TexturePaint throws InternalError: Surface not cachable

I have a custom Icon which uses a TexturePaint as paint and calls fillPolygon on a Graphics2D object. This code works fine on JDK6 and JDK7, but fails under JDK8 with 64bit Linux (tried most recent JDK1.8 on 64bit Linux). On Windows, this runs fine…
Robin
  • 36,233
  • 5
  • 47
  • 99
7
votes
1 answer

How to draw inner stroke with Java2D

I just want to draw the circle which is exactly 15x15 pixels sized, and have fill and outline. I'm using Java2D. The problem is, as a result of sequentally called Graphics2D.fill(circle) and Graphics2D.draw(circle) the circle of 16x16 pixels drawn.…
xmichael91
  • 156
  • 10
7
votes
1 answer

How can I save a BufferedImage to be below a particular size

(Using java 8) Given a image user needs to be able to specify min/max image size in pixels and also maximum size of saved image in kbs, image is saved as jpg. So I have the first bit working, by resizing buffered image: public static BufferedImage…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
7
votes
2 answers

creating a rectangle from 2 specific points

I am trying to create a rectangle in Java but only with awt package classes. I can only click two points and the program must calculate the width and height and draw a rectangle between those exact two points. The following doesn't work for…
Sean Connell
  • 71
  • 1
  • 1
  • 2
7
votes
2 answers

How do I load an enormous image to Java via BufferedImage?

I want to load large images (18000 x 18000) to my application. If i use BufferedImage with type int_rgb, I need around 1235mb of heap memory to load. This is a very high amount of memory, and end users will likely have less ram (1GB or less). On…
Mihir
  • 2,480
  • 7
  • 38
  • 57
1 2
3
71 72