java-2d

Moving an Ellipse that has been drawn [closed]

二次信任 提交于 2019-12-25 07:39:17
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . So I add an Ellipse2D.Float to a JPanel (and to an ArrayList) when clicked. I want to know if after this has been done I can then move the shape (say, through shift-click). At the moment it seems to be static and I cannot drag it anywhere. Furthermore, is it possible to connect two circles with a line in such a

Porting graphics drawing from android to standard java

假装没事ソ 提交于 2019-12-25 02:38:14
问题 I have an android application which draws images directly onto the canvas. It uses notably paths and beziers. I now need to port this to a windows app written in standard java and am having difficulty in finding the correct graphics library to use. I need to create bitmaps in memory, drawn with a path. The path needs to be able to hold lines, beziers, ovals and hollow rectangles. The resulting image is then blitted into the output graphic a number of times. I have looked at Graphics2D, but

Antialias height map edge using Java 2D

眉间皱痕 提交于 2019-12-25 01:46:03
问题 I'm using Java 2D to render a terrain map. Terrain Map looks like this: You can see how the edges are rather jagged. I want to render the edge of the terrain smoothly, but turning on antialiasing with RenderingHints doesn't work because I render the terrain map one column at a time. Here's my code to render the terrain: // terrainImageG2 renders to a BufferedImage, obtained via BufferedImage.createGraphics() terrainImageG2.setBackground(Color.WHITE); terrainImageG2.clearRect(0, 0, NUM_WIDE,

How to rotate an imageIcon in Java

亡梦爱人 提交于 2019-12-24 22:01:18
问题 I'm creating a domino game in java. I have the following code that loads, resizes and then display the domino image on the screen: ImageIcon imageIcon = new ImageIcon("images\\4-4.png"); Image image = imageIcon.getImage(); Image newimg = image.getScaledInstance(60, 120, java.awt.Image.SCALE_SMOOTH); imageIcon = new ImageIcon(newimg); JLabel img = new JLabel(imageIcon); img.setBounds(100, 100, 60, 120); getContentPane().add(img); What I want to do is rotate the image either 90 or -90 degrees.

Java: Fastest way to draw text?

廉价感情. 提交于 2019-12-24 18:39:55
问题 I'm trying to write a program that just creates an image out of text (e.g. write "hello" on a white square and store the image), which sounds simple but it must be done quickly. I tried the Java2D library but drawing onto a BufferedImage takes ~2 seconds to just draw the image, not even save or display it. I also tried Java-based CAPTCHA generators but they take much too long (5 seconds). This seems like simple enough task to just draw text, but I'm frustrated that I can't do this faster than

How to create a circular bufferedimage rather than creating a rectangular one in Java using Graphics

我只是一个虾纸丫 提交于 2019-12-24 12:37:02
问题 I need to create a bufferedimage (circular type) but I am able to create only rectangular type. Then I want to create a oval inside the bufferedimage with some configurations and finally i want to draw a rectangular icon inside the circular shape which should be inserted on the circular shape and not on the rectangular bufferedimage. Now i am able to do the following BufferedImage img = "SomeImage.png"; BufferedImage bfImage = new BufferedImage(200,200,BufferedImage.TYPE_INT_ARGB); Graphics2D

Java Swing: Mouse cursor misbehaves when held over a rectangle

。_饼干妹妹 提交于 2019-12-24 12:28:00
问题 I need to change the cursor while it moves over an array-list of rectangles by the contain(p) method.The problem is My first algorithm to use an iterator to iterate through the rectangles doesn't work as expected.The cursor only changes when hovering over the first rectangle,in the other rectangles neither does it respond by showing the cursor changing nor indicate through the console that the cursor is hovering above them?!! My second solution also refuses to work properly.I use a for loop

Checking if a rectangle intersects text

别等时光非礼了梦想. 提交于 2019-12-24 10:59:35
问题 I have a class called 'MapObject' which allows you to define what it is, what it does. I have recently added text to this, and it works fine however the collisions is a rectangle, which in some scenarios isn't horrible, however I would prefer to have a collision box matching the text (aka check if a 1x1 rectangle collides with the text but can still be inbetween letters) I have tried the following: GlyphVector vec = ob.font.createGlyphVector(new Canvas().getFontMetrics(ob.font)

what is path & subpath in Java2D?

一笑奈何 提交于 2019-12-24 08:33:10
问题 I hope it is not a silly question: What is path, subpath, and endpoint in Java2D? 回答1: Most commonly, a path is a combination of lines and cubic Bezier segments. This is represented procedurally by a sequence of moveTo, lineTo, curveTo, and closePath methods. These correspond to the operators of the same name in PostScript (but lowercased), from which the Java2D imaging model derives. (Also, there is quadTo, which is a quadratic Bezier segment, but this is less important and easily simulated

Drawing a triangle in java

痞子三分冷 提交于 2019-12-24 08:06:19
问题 So a section of my assignment is to make a triangle class to be linked to various buttons...but I'm not sure how to make one in eclipse. The specific instructions say this: Create a triangle class Data fields: Point[] coords; constructors Implement all abstract methods defined in superclass Getters and setters for each data field Override public void paint(Graphics arg0) method I have everything set up in the other classes..except for the triangle class. I'm confused on how to create a