graphics2d

Resize Graphics2d into JScrollPane

流过昼夜 提交于 2019-12-29 09:05:54
问题 In connection with question Resizing a component without repainting is my question how to create resiziable custom Graphics2d in form import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ZoomWithSelectionInViewport implements MouseWheelListener { private JComponent b; private int hexSize = 3; private int zoom = 80; private JScrollPane view; public ZoomWithSelectionInViewport() throws Exception { b = new JComponent() { private static final long serialVersionUID = 1L;

Drawing a line on a JFrame

余生长醉 提交于 2019-12-29 07:32:28
问题 I am trying to draw a line using the Graphics 2D but then the line appears over all the other components in the JFrame thus making them invisible. How do I correct this problem? Here's the code : import javax.swing.*; import java.awt.*; import java.awt.geom.*; class Success extends JFrame{ public Success(){ JPanel panel=new JPanel(); getContentPane().add(panel); setSize(450,450); JButton button =new JButton("press"); panel.add(button); } public void paint(Graphics g) { Graphics2D g2 =

Interoperability between Graphics2D and GraphicsContext

你说的曾经没有我的故事 提交于 2019-12-29 04:45:15
问题 I am working with a group which is looking to target a graphics renderer in Java. At the moment I am trying to figure out whether targeting java.awt.Graphics2D will be forward compatible. Namely, can other libraries like JavaFX display renders from a Graphics2D instance? Is there interoperability between java.awt.Graphics2D and javafx.scene.canvas.GraphicsContext ? Or, if not between Graphics2D and GraphicsContext directly, is there any means of displaying a Graphics2D render in a JavaFX

getting the right image observer for rotating an image

£可爱£侵袭症+ 提交于 2019-12-29 02:01:13
问题 So Im drawing a BufferedImage 'bird' but I want to rotate it according to the angle that it is falling. I have a bird object which contains the BufferedImage and a render() method which draw it rotated. public void render(Graphics2D g, ImageObserver io) { double theta = Math.tan((height - pastHeight) / .875); System.out.println(theta); Graphics2D g2 = (Graphics2D) bird.getGraphics(); g2.drawImage(bird, 100, (int) height, null); g2.rotate(theta); g2.drawImage(bird, 100, (int) height, io); } I

Drawing an object using getGraphics() without extending JFrame

回眸只為那壹抹淺笑 提交于 2019-12-27 10:40:07
问题 How can I draw an object without a class (which extends JFrame )? I found getGraphics method but it doesnt draw the object. import javax.swing.*; import java.awt.*; public class Main { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setSize(600, 400); JPanel panel = new JPanel(); frame.add(panel); Graphics g = panel.getGraphics(); g.setColor(Color.BLUE); g.fillRect(0, 0, 100, 100); } }

How to crop a polygon from BufferedImage

烈酒焚心 提交于 2019-12-25 14:22:27
问题 How to crop a polygon shaped portion of BufferedImage and write it to another BufferedImage? 回答1: Graphics2D has clip(Shape) and draw(Shape) methods. So I would guess you can set the Shape to be your polygon and then paint from one BufferedImage to the other. 来源: https://stackoverflow.com/questions/4997473/how-to-crop-a-polygon-from-bufferedimage

How to crop a polygon from BufferedImage

三世轮回 提交于 2019-12-25 14:22:10
问题 How to crop a polygon shaped portion of BufferedImage and write it to another BufferedImage? 回答1: Graphics2D has clip(Shape) and draw(Shape) methods. So I would guess you can set the Shape to be your polygon and then paint from one BufferedImage to the other. 来源: https://stackoverflow.com/questions/4997473/how-to-crop-a-polygon-from-bufferedimage

Java - Drawing a dynamic shape outline

↘锁芯ラ 提交于 2019-12-25 12:43:16
问题 I wish to create a dynamic outline to a Shape (AWT) by adding objects (with draw functions) to appropriate positions on screen along the shape's perimeter. I want a roughly even distance between each object. (An alternative approach to the same affect will be fine.) How might I acquire the locations for these objects? I know shapes have a path iterator, but I have no idea how to use it. 回答1: You might look at a library such as the one described in A Shape Diagram Editor. If you want to

Graphics2D does PostModern

自闭症网瘾萝莉.ら 提交于 2019-12-25 05:02:23
问题 In the following code changing fill to draw produces unexpected results. The attached image demonstrates the undesired but much appreciated postmodern effect caused by draw ing the red and green rectangles. The affine transform should not be part of the problem, but as Holmes said, once you rule out all other possibilities ... So, I will explain the transform. I solved a bunch of equations to figure out how to make the window show a cartesian coordinate system with (-2, -2) in the lower left

How to rotate image at a specific point by a certain angle in java?

☆樱花仙子☆ 提交于 2019-12-25 03:08:52
问题 I want to rotate an image about a specific pixel position and not about the centre of the image. I want to rotate the image by certain degrees less than 90. I've made use of rotate function of the graphics class but i get the image blurred when rotated. How to remove this blur? Is there a specific function for this? This is the code i am using right now: BufferedImage oldImage = ImageIO.read(new File("C:/omr/OMR_Rotation_1.jpg")); BufferedImage newImage = new BufferedImage(oldImage.getWidth()