graphics2d

How to rotate a rectangle in 3d space using an axis as a HINGE?

▼魔方 西西 提交于 2019-12-11 10:12:55
问题 I'm looking forward mathematical or algorithmic calculation of rotating a rectangle with a fixed axis as a HINGE. As you can see in the below picture. I have positions (x,y) of 4 points of rectangle vertices, and the origin is center of the rectangle, so the desired algorithm will project my original shape's vertices into the desire shape vertices. (Please see image below) I know it's easy to do it with 3d libraries but i need to do it with 2d graphics in a high-level programming language

Paint on a glass pane without repainting other components

给你一囗甜甜゛ 提交于 2019-12-11 09:27:00
问题 Let's say I have a JPanel called content with its paintComponent(g) overridden. This panel usually paints very quickly, but sometimes ( Clarification: the user generates a graphics object that can have thousands of points, which slows down the rendering. It needs to be this way and it's not part of my question) it may take a whole second to repaint due to all of the graphics stuff going on in it. I want to paint a dot near the location of the mouse, but I want this to update quickly and not

Affine transformation in linear RGB space

我与影子孤独终老i 提交于 2019-12-11 09:24:41
问题 If the source raster in linear RGB color space is transformed using the following Java code, the java.awt.image.ImagingOpException: Unable to transform src image error is thrown when the filter is applied (the last line). ColorModel linearRGBColorModel = new DirectColorModel( ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), 32, 0xff0000, 0xff00, 0xff, 0xff000000, true, DataBuffer.TYPE_INT); WritableRaster srcRaster = linearRGBColorModel.createCompatibleWritableRaster(100, 100);

Java2D Unacceptable Frame Rate

前提是你 提交于 2019-12-11 09:19:59
问题 Java2D Game Running 20-30 FPS I am writing a java2D game that as of now has an almost perfect memory footprint running only at around 2% of about a 4GB usable RAM space. The problem is the game only is running at around 20-30 fps just from rendering the character and the surrounding environment. I read already something about utilizing the GraphicsConfiguration, but when I tried that my fps soared right up to 120-130 fps while my memory increased to 70-80% and the frame was frozen in one

repaint() not calling PaintComponent to use Graphics2D

流过昼夜 提交于 2019-12-11 06:44:28
问题 I have spent a few days now trying to get the Graphics2D class to work within my code. I have it structured in such a way that when a click event is registered the call to repaint is done, however this only produces a nullpointer exception when it reaches the stage of calling repaint(). It is all working as expected when debugging and not called from within the paintComponent method, however when trying to call the code properly using paintComponent and repaint() to allow the Graphics2D class

Graphics2D Rotation Precision Issues

删除回忆录丶 提交于 2019-12-11 06:37:31
问题 I am drawing 4 stacked rectangles, rotating the canvas about a point and then drawing that same shape again but the stacked rectangles aren't remaining completely aligned. Here's a screenshot: As you can see, the first, unrotated block is perfect but the following ones are misaligned. Why is this happening and how can I prevent it? SSCE //Just import everything to keep it short and sweet import java.awt.*; import java.awt.geom.*; import javax.swing.*; @SuppressWarnings("serial") public class

JScrollPane & Graphics2D

痴心易碎 提交于 2019-12-11 05:17:30
问题 I am trying to draw graphics that is bigger than the JFrame and use JScrollPane to scroll the entire graphics. I created a simple example with two lines. The scroll bars appear but the graphics do not show. import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; public class Test extends JPanel{ public static void main(String... args) { Test test = new Test(); JFrame frame = new

Force full redraw of a Jpanel Java2D

不打扰是莪最后的温柔 提交于 2019-12-11 03:09:16
问题 My question is that i need to make a GUI that keeps updating becuse i get values that can change from a DB and i got some problems in the graphical area. well im using Drawline and Drawstring from Graphics2D that print values that are found on the database, this strings and lines move and change value, so i need to call repaint(); with a timer to make them apper in the jpanel, the problem is that repaint(); is not removing the old painting in the background before painting, but when i resize

Graphics2D - Rotating Shapes on a Graphics2D object

≡放荡痞女 提交于 2019-12-11 00:55:57
问题 I have a Graphics2D object which I use to draw on my Canvas . I draw multiple shapes on the Canvas and want to transform only one (or part) of them. I'll try to keep this simple: void render(Graphics2D g) { ... // Draw shape 1 ... // Draw shape 2 ... // Draw shape 3 } How would I go about rotating shape 2 while leaving shape 1 and 3 intact? By "rotate" I mean rotating around its center point, which we can define as x and y for example. I've been looking for a way to do this for a while now,

Trying to add a dynamically positioned image in a JPanel on a button click

风格不统一 提交于 2019-12-10 21:46:54
问题 I am trying to add/draw a single Graphics object to an existing JPanel. I am generating 10 initial Graphics objects randomly sized and place in the panel, but would like to add additional drawn objects one a time, randomly sized and placed like the initial 10. Currently, the AddNewDrawItem class is not rendering the new Graphics object. Thank you for input. import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random