graphics2d

Multiple instances of the same animated GIF in a Canvas (Java)

坚强是说给别人听的谎言 提交于 2019-12-23 18:20:13
问题 So I'm making a game where you can put bombs on the location of your character. Each bomb is associated with a GIF image when the bomb is displayed and eventually go BOOM (think about Bomberman). The problem was, when i tried to paint more than one bomb on the screen, it was painted from the last frame of the GIF. Investigating, I found the method image.flush() to reset the GIF cicle but now the problem is that every time I paint a second bomb on the screen, the GIF cycle is reset for all

How to scale a Graphics2D image with transparent padding

家住魔仙堡 提交于 2019-12-23 18:04:20
问题 I'm trying to write a small method which takes a BufferedImage image and a new width and height and scales the image keeping the aspect ratio by adding transparent border to the left/right or top/bottom depending on the image. The scaling works fine but for the life of me I can't get the border to be transparent. So far I have the following code posted on pastebin.com which does the scaling well. I've read a lot of manuals and other SO questions to no avail. I've tried numerous permutations

How to Drawing a curve line(peaks) using list of x,y coordinates

て烟熏妆下的殇ゞ 提交于 2019-12-23 17:10:00
问题 I have a list of x,y points which printed,display an uneven peak curve line. The above image was generated by just painting the points on a java paint component. I used the following way to paint them on a paint component. g.drawline(pointX,pointY,pointX,pointY) Are there better ways to paint such wave line? I checked some of the similar questions,often they need to print a curve or peak,but my line is not always a peak as some times its flats out and other times they are bizarre. 回答1: The

Rotation transform not working properly in repaint when running thread

孤街浪徒 提交于 2019-12-23 15:39:12
问题 I have been working on trying to make this program work, even though I can't seem to find whatever is the problem. This program is made of the following 2 classes, no more, no less. It is basically supposed to draw a point on each click in the drawing zone, and on the 3rd click all points are connected. I still have to work on making it prettier and more accurate, but this part works. What doesn't work is what should follow : on the fourth click a thread should start (and it starts), and the

Graphics2D: Should I use the int or float versions?

我们两清 提交于 2019-12-23 12:41:59
问题 Some of the Graphics2D methods, such as drawString , have versions that take coordinates as int or float . Are there any reasons to choose one over the other? Likewise, should I use the newer Shape classes, such as Rectangle2D (which use floating-point coordinates), or use Rectangle (which defines coordinates as int s)? 回答1: I see int and float - drawString(AttributedCharacterIterator iterator, float x, float y) Renders the text of the specified iterator, using the Graphics2D context's

BufferedImage not displaying (all black) but Image can be displayed

一个人想着一个人 提交于 2019-12-23 10:26:32
问题 I'm new to Java graphics (computer graphics in general) and Stack Overflow, so please help me out and help me phrase my problem better. At the moment, I'm trying to display a BufferedImage alongside the original image in a Java GUI. This is my code: Image oriImage = robot.getQwerkController().getVideoStreamService().getFrame(); //load the original image Graphics2D hi = bufferedImage.createGraphics(); hi.drawImage(oriImage, 0,0, null); //draw the original image into the BufferedImage hi

Kerning problems when drawing text character by character

爷,独闯天下 提交于 2019-12-23 10:19:48
问题 I'm trying to draw strings character by character to add lighting effects to shapes composed of text. while (i != line.length()) { c = line.substring(i, i + 1); cWidth = g.getFontMetrics().stringWidth(c); g.drawString(c, xx += cWidth, yy); i++; } The problem is, the width of a character isn't the actual distance it's drawn from another character when those two characters are printed as a string. Is there any way to get the correct distance in graphics2d? 回答1: The answer by Lukas Baran solves

Hilbert Curve in Applet with Matrix of coordinates

余生颓废 提交于 2019-12-23 04:28:25
问题 I am trying to approximate a solution of the Traveling Salesman Problem with a Hilbert Curve program. I have to do it by using an applet. How would I add the Matrix in my code, and how would I display the coordinates in the Applet. I don't need to have more than one frame. The code is below: import java.awt.*; import java.applet.*; // Background images (put a map in the back of the applet) public class HilbertCurve extends Applet{ private SimpleGraphics sg = null; private final int dist0=512;

Java Graphics2D is Drawing One Pixel Off (Rounding error?)

梦想与她 提交于 2019-12-23 02:29:09
问题 I have been trying to make a program in Java using Graphics2D and PaintComponent. However, Java is not rounding some values correctly resulting in a few points being rendered a pixel different from where it supposed to be which gives an unclean image. You can see what I mean in the picture below. Here is my code. What can I change to fix this? Thank you! public void paintComponent( Graphics g ) { super.paintComponent( g ); g.setColor(Color.red); int orginX = getWidth()/2; int orginY =

how java graphics repaint method actually works

穿精又带淫゛_ 提交于 2019-12-23 02:04:37
问题 I've just started working with java 2d graphics applications, on my studies repaint is redrawing our graphics wasting a lot of resources. but I want to know what repaint is, does and how to use it efficiently, thread safely and fast for many movable dynamic objects on my canvas? 回答1: I would start by having a read through Performing Custom Painting and Painting in AWT and Swing repaint makes a request to the RepaintManager to paint part or all of a component. The RepaintManager will decide