graphics2d

SVG to Java Graphics2D

北战南征 提交于 2019-12-04 11:46:00
Can anyone suggest some good way to generate Graphics2D object form SVG data? I've seen Apache Batic lib, but it seams that they use some JSVGCanvas that gets the URI etc… And I want a Graphics2D stuff instead of JComponent. Thanks for any suggestions! Try to look at SVG Salamander library. On this page there are some starting tips. It's a good thing if You want only to draw some svgs. You can also use the Flamingo SVG Transcoder , it generates pure Java2D code from a SVG file with no external dependencies. 来源: https://stackoverflow.com/questions/9939727/svg-to-java-graphics2d

Painting pixels images in Java

空扰寡人 提交于 2019-12-04 11:28:29
问题 Which method is the best way to create a pixel image with java. Say, I want to create a pixel image with the dimensions 200x200 which are 40.000 pixels in total. How can I create a pixel from a random color and render it at a given position on a JFrame. I tried to create a own component which just creates pixel but it seems that this is not very performant if I create such a pixel a 250.000 times with a for-loop and add each instance to a JPanels layout. class Pixel extends JComponent {

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

ぐ巨炮叔叔 提交于 2019-12-04 05:37:47
问题 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

java: Graphics2D version of polyline?

淺唱寂寞╮ 提交于 2019-12-04 04:13:43
问题 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() ? 回答1: 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 =

Can you increase line thickness when using Java Graphics for an applet? I don't believe that BasicStroke works [duplicate]

拜拜、爱过 提交于 2019-12-04 00:40:35
This question already has an answer here: Java2D: Increase the line width 2 answers I am having trouble adjusting line thickness. Can I do that in Graphics or do i have to do it in Graphics2D? If so, how do I alter the program to make it run? Thanks! import java.applet.Applet; import java.awt.*; public class myAppletNumberOne extends Applet { public void paint (Graphics page) { //Something here??? } } Yes you have to do it in Graphics2D, but that's hardly an issue, as every Graphics in Swing is a Graphics2D object (it just keeps the old interface for compatibility reasons). public void

Getting string size in java (without having a Graphics object available)

限于喜欢 提交于 2019-12-04 00:00:58
问题 I'm trying to write application which need to draw many strings using Graphics2D class in Java. I need to get sizes of each String object (to calculate exact position of each string). There is so many strings that it should be done before the paint() method is called and only once at the beginning of my program (so then I don't have Graphics2D object yet). I know that there is a method Font.getStringBounds() but it needs a FontRenderContext object as a parameter. When i tried to create my own

Align text to the right in a TextLayout, using Java Graphics2D API

删除回忆录丶 提交于 2019-12-03 20:56:17
So, I'm using the code in Java tutorial to draw a piece of text, but I don't know how to align text to the right margin. I just included attstring.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL); in the code for that case but it doesn't work. protected float drawParagraph (Graphics2D g2, String text, float width, float x, float y, Boolean dir){ AttributedString attstring = new AttributedString(text); attstring.addAttribute(TextAttribute.FONT, font); if (dir == TextAttribute.RUN_DIRECTION_RTL){ attstring.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN

Java graphics repaint problem

寵の児 提交于 2019-12-03 20:23:41
Having trouble with a simple paint pad in java. Issues with getting my clear button to repaint. The array is clearing but not repainting. Can anyone spot my problem or is there any different way of generating a clear button for this code. public class DrawingPanel extends JPanel { private double x1=0; private double x2=0; private double y1=0; private double y2=0; private ArrayList<Shape> myArr = new ArrayList<Shape>(); //private ArrayList<Shape> clearMyArr = new ArrayList<Shape>(); ButtonPanel buttonPress; public void paintComponent(Graphics g) { for (Shape i : myArr) { Graphics2D g2d =

Understand BufferStrategy

对着背影说爱祢 提交于 2019-12-03 18:53:11
问题 I'm kind of new to java. I want to make a game. After a lot of research, I can't understand how bufferstrategy works.. I know the basics.. it creates an off-screen image that you can later put into your windows object.. I got this public class Marco extends JFrame { private static final long serialVersionUID = 1L; BufferStrategy bs; //create an strategy for multi-buffering. public Marco() { basicFunctions(); //just the clasics setSize,setVisible,etc createBufferStrategy(2);//jframe extends

Java - Creating a 2D tile map in a panel using Graphics2D Rectangles?

人走茶凉 提交于 2019-12-03 10:20:52
问题 I'm trying to simulate a battle in a really basic program, but since this is my first time with a big program in Java I'm pretty much clueless on how to proceed. I was thinking I'd have a big 600-by-600 panel and use Graphics2D to just draw the terrain as 20x20 rectangles... Unfortunately even with several tutorials I have no idea what to do. I have 10 different types of terrain to cycle through, and 5 different landscape profiles. Basically what I want the program to do is when I select a