java-2d

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

◇◆丶佛笑我妖孽 提交于 2019-12-03 13:28:13
问题 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 colours in my PNG image (3rd image down the right hand side). If it's not possible with Java 2D, is there a library out there that will allow me to do this effectively? 回答1: I think Martijn Courteaux was right: Here is example implementation: import

Low-hanging graphics programming fruits?

假装没事ソ 提交于 2019-12-03 08:46:14
I'm currently working on a tile-based game in Java2D, and I was thinking of adding some cheap eye candy. For example, implementing a simple particle system (maybe something like this ) for explosions and/or smoke. Do you have any suggestion for relatively easy to program effects that wouldn't require drawing a lot (or at all) of new art? Tutorials and code samples for said effects would also be most welcome! -Ido. PS - if absolutely necessary I could switch to something like LWJGL/JOGL or even Slick - but I rather stay with Java2D. Implementing blurs and other image filtering effects are

Drawing a nice circle in Java

懵懂的女人 提交于 2019-12-03 07:35:35
I'm using Java Graphics and I keep getting "ugly" circles. Here's what my Java program makes And here's the same thing being made in Matlab I think it is clear that the Java one is not as "nice" looking as the Matlab one, particularly on the edges of the circle. Note that this has nothing to do with the resolution...these images are practically the same size. Also note that I am already setting rendering hints. Here's a stand alone with a Main function you can run to test this out. package test; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt

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

可紊 提交于 2019-12-03 03:29:11
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 colours in my PNG image (3rd image down the right hand side). If it's not possible with Java 2D, is there a library out there that will allow me to do this effectively? I think Martijn Courteaux was right: Here is example implementation: import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.awt.image.IndexColorModel; import

Java 2D scene graph library for GUI

可紊 提交于 2019-12-03 00:45:27
I'm looking for a 2D scene graph library for building GUI applications. It should be fast, using Java2D and be compatible with Swing (embeddable in a Swing app and also display Swing components). Support for animations is a plus. Do you have any experience with some of the libraries? Are there any libraries that I have missed? I have to add that I'm not totally offended by a Scala library. Project Scene Graph seems reasonably fast only GPL (no LGPL) supports animations abandoned 2 years ago as former part of JavaFX it's a Sun product G dunno whether it's fast LGPL no animations last version

How do I make a (keyPressed) KeyListener?

你。 提交于 2019-12-02 21:22:15
问题 Im trying to write a very simple program that allows you to control a sprite with arrow keys and move around the screen. From what I understand, to do this I need a keyPressed() KeyListener . I believe Im doing this correctly based on the Java Doc but its not returning the correct output when I press the designated key. Can someone please tell me what is wrong with my code, and if possible, provide a simple example of the usage of this class? Thanks! (Note, code is unfinished) import java.awt

Graphics - How do I use the method create(int x, int y, int width, int height) and translate(int x, int y)?

冷暖自知 提交于 2019-12-02 18:07:46
问题 I was trying to do my computer science homework but I am stuck as I was trying to use the following methods. public Graphics create(int x,int y,int width,int height) That Creates a new Graphics object based on this Graphics object, but with a new translation and clip area. Parameters: x - the x coordinate. y - the y coordinate. width - the width of the clipping rectangle. height - the height of the clipping rectangle. public abstract void translate(int x,int y) That Translates the origin of

custom shape rotation issue

不问归期 提交于 2019-12-02 17:46:20
问题 I am trying to rotate a custom shape around its center, but can not get the result as expected. what i want is * shape should be rotated around its center without moving itself. * what my solution is currently doing is rotating a whole shape around its center , by every rotation its changing its position. I have multiple shapes so i have created a class to encapsulate a shape with its transform in following class public abstract class Shoe implements Shape, ShoeShape { // variable declaration

understanding difficulties java swing

北城以北 提交于 2019-12-02 13:19:45
im trying to paint random (not yet) circles on a JPanel through click on a JMenu. Im using a JTextField (and have to keep this) for some output. Here is my Class: class RandomDrawer extends JPanel implements ActionListener { @Override public void actionPerformed(ActionEvent e) { //double x = Math.random(); //double y = Math.random(); Random generator = new Random(); int x = generator.nextInt(100)+1; int y = generator.nextInt(100)+1; //System.out.printf("x = %d y = %d\n", x, y); status.setText(String.format("rnd draw x: %d y: %d", x, y)); Graphics2D gg = (Graphics2D) canvas.getGraphics(); gg

How do I make a (keyPressed) KeyListener?

感情迁移 提交于 2019-12-02 10:32:34
Im trying to write a very simple program that allows you to control a sprite with arrow keys and move around the screen. From what I understand, to do this I need a keyPressed() KeyListener . I believe Im doing this correctly based on the Java Doc but its not returning the correct output when I press the designated key. Can someone please tell me what is wrong with my code, and if possible, provide a simple example of the usage of this class? Thanks! (Note, code is unfinished) import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event