graphics2d

ImageIO saves back to original size

浪尽此生 提交于 2019-12-02 05:54:22
I've been searching for some solutions from the internet yet I still haven't found an answer to my problem. I've been working or doing a program that would get an image file from my PC then will be edited using Java Graphics to add some text/object/etc. After that, Java ImageIO will save the newly modified image. So far, I was able to do it nicely but I got a problem about the size of the image. The original image and the modified image didn't have the same size. The original is a 2x3 inches-image while the modified one which supposedly have 2x3inches too sadly got 8x14 inches. So, it has gone

Rotate rectangle and move it in sin wave - Help using graphics2D

南楼画角 提交于 2019-12-02 05:40:58
问题 Hi! I have the code below using previous Stackoverflow posts. I want to just rotate the rectangle by some angle and make it move in sin wave. This code rotates the whole sin wave too. I understand why it is happening , but I don't know how to achieve my intention. please help!!! Thanks a lot for taking time. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java

How can I draw a curved line segment using QuadCurve2D.Double?

自闭症网瘾萝莉.ら 提交于 2019-12-02 05:12:30
Here is the line of code where I declare the curve: QuadCurve2D.Double curve = new QuadCurve2D.Double(50,100,100,170,150,100); Now what code can I use to draw this curve? I tried something like: g.draw(curve); but obviously that didn't work. Any suggestions? I've made a minimum test case of what I think your describing here. This program works but I can't really help you unless I can see the code you are working with. import java.awt.geom.*; import java.awt.*; import javax.swing.*; public class CurveDraw extends JFrame { public static void main(String[] args) { CurveDraw frame = new CurveDraw(

drawPolygon keeps drawing lines from starting (mousePressed) location to current (mouseDragged) location

橙三吉。 提交于 2019-12-02 03:19:37
So, I'm trying to dynamically draw a Polygon starting from when I click the mouse until I stop dragging and release. Instead of, for the purpose of this question, a square outline being drawn when I click, drag down, then right-across, then up, then left-across, this is what happens: http://imgur.com/t8ZN3Pp Any suggestions? Notes: model.addPolygon() creates a Polygon with starting points and adds it to an ArrayList called 'polys' model.addPolygonPoint() adds points to this created polygon that is stored in 'polys' my paint function iterates through polys to paint public void mousePressed

Cartesian Plane in Java

[亡魂溺海] 提交于 2019-12-02 03:13:59
问题 After learning cycles, arrays, methods,...I started playing around with graphics but I encountered some problems. I was looking for some example when I saw this one: http://javaceda.blogspot.ch/2010/06/draw-cartesian-coordinate-system-in.html It provides an example of a cartesian plane in Java. I can understand pretty much everything of that code ( except a few lines like invokelater, SwingUtilities and I will take a look at them later..). Let's say that now I want to create a class "Point"

JComponent size issue

本秂侑毒 提交于 2019-12-02 02:52:32
问题 I have a JComponent subclass that I am using to draw shapes onto my screen. In the constructor, I am trying to set ballX and ballY to half of the X and Y size values of the JComponent , and I think I am doing it wrong. I have looked this up a lot now, and cannot find a remedy. The code is as follows. Please bear in mind that this is my first real Swing/Graphics2D venture. public class PongCanvas extends JComponent { //Vars to hold XY values and Dimension values. private int batXDim, batYDim;

JComponent size issue

醉酒当歌 提交于 2019-12-02 02:05:46
I have a JComponent subclass that I am using to draw shapes onto my screen. In the constructor, I am trying to set ballX and ballY to half of the X and Y size values of the JComponent , and I think I am doing it wrong. I have looked this up a lot now, and cannot find a remedy. The code is as follows. Please bear in mind that this is my first real Swing/Graphics2D venture. public class PongCanvas extends JComponent { //Vars to hold XY values and Dimension values. private int batXDim, batYDim; private int b1X, b1Y; private int b2X, b2Y; private int ballRad, ballX, ballY; public PongCanvas() {/

java: Graphics2D version of polyline?

◇◆丶佛笑我妖孽 提交于 2019-12-01 22:09:35
OK, so there's a Line2D and a Rectangle2D that can be used by Graphics2D.draw() instead of Graphics.drawLine() and Graphics.drawRectangle() . Is there a similar "upgrade" for Graphics.drawPolyLine() ? Have a look at Path2D . It is a Shape and should thus be able to be drawn through Graphics2D.draw() . Example usage: import java.awt.*; import java.awt.geom.Path2D; import javax.swing.*; public class FrameTestBase extends JFrame { public static void main(String args[]) { FrameTestBase t = new FrameTestBase(); t.add(new JComponent() { public void paintComponent(Graphics g) { Path2D p = new Path2D

Issues Creating a Pen Tool with Java's Path2D

倾然丶 夕夏残阳落幕 提交于 2019-12-01 20:58:09
I've been attempting to create a pen tool for my Java drawing program using the Path2D class in conjunction with mouse listeners, but I've had baffling results. The tool will work for several seconds, but then the entire application will freeze and will have to be closed. (No exceptions occur here; the program just freezes). Here's an SSCCE that demonstrates the issue: import java.awt.BasicStroke; import java.awt.event.MouseAdapter; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Shape; import java

Java moving a circle in a gui with arrow keys

回眸只為那壹抹淺笑 提交于 2019-12-01 11:58:05
I am trying to move a circle left with a keyEvent. So far, the circle is drawn on the window but it does not move left! I feel like the problem is where I add the Window() constructor to the container. The is no output on the console to tell me that it is working. So I dont think it even reaches the KeyEvent class. Here is my code: import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import javax.swing.*; public class Window extends JPanel { private static Ellipse2D.Double circle; public Window() { super(); int width = 400; int height = 400; circle = new Ellipse2D.Double