java-2d

Graphics2D setfont() heavily slows down the start up of java application

独自空忆成欢 提交于 2019-12-12 13:57:10
问题 Hi guys I'm making a game by java and it refreshes itself 60 times per second. Every time it executes a loop and I use g2d to draw images and strings. Things work fine if I do g2d.setFont(new Font("Arial", Font.PLAIN, 8)); and drawstring and it would be normal, but if I set the font to some "unfamiliar" fonts and do the same thing, the swing would show white screen in the first second of start up then paint everything correctly and it's apparently too slow.(2 secs) I put a jpanel in a jframe

Why does this code throw a java.lang.NullPointerException?

若如初见. 提交于 2019-12-12 12:38:50
问题 I have found a source code and i added it to my frame just for testing which it uses Java2D. But it thows an exception. I don't understand why. my class: package ClientGUI; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.MediaTracker; import java.awt.RenderingHints; import java.awt.geom.CubicCurve2D; import java.awt.geom.PathIterator; import java.awt.geom.Point2D; import java.awt.image.BufferedImage; /** * * @author ICC *

How do I convert an enormous TIFF image to PNG/JPEG without out of memory error?

纵然是瞬间 提交于 2019-12-12 10:54:28
问题 i have a tiff file 18000 * 18000 in Dimension and 1.20 GB in size. the tiff has 72 DPI. I want to convert this TIFF to PNG/JPEG using 400 DPI. I am using following code to do it public static void ConvertTiffToJpg(String str_TiffUrl, String str_JpgFileDestinationUrl) throws Exception { try { FileSeekableStream obj_FileSeekableStream = new FileSeekableStream( new File(str_TiffUrl)); ImageDecoder obj_ImageDecoder = ImageCodec.createImageDecoder( "tiff", obj_FileSeekableStream, null);

How do I do double buffering in Java2D?

纵饮孤独 提交于 2019-12-12 10:49:19
问题 I'm drawing a bunch of primitives using Java2D on the screen and I'm getting a lot of tearing/flicker. How can I enable/use double-buffering so it draws it off screen then shows the whole thing? 回答1: Check out this tutorial about double buffering: http://gpwiki.org/index.php/Java:Tutorials:Double_Buffering 回答2: Some tips to use buffering effectively as a programmer view and some testing programs are avaliable 回答3: 1) You create a BufferedImage instance. For max performance you want to make

Java 2D: Moving a point P a certain distance closer to another point?

旧街凉风 提交于 2019-12-12 10:43:26
问题 What is the best way to go about moving a Point2D.Double x distance closer to another Point2D.Double? Edit: Tried to edit, but so went down for maintenance. No this is not homework I need to move a plane (A) towards the end of a runway (C) and point it in the correct direction (angle a). alt text http://img246.imageshack.us/img246/9707/planec.png Here is what I have so far, but it seems messy, what is the usual way to go about doing something like this? //coordinate = plane coordinate

What are some faster alternatives to Java2d?

六眼飞鱼酱① 提交于 2019-12-12 07:41:46
问题 I'm looking to do some physics simulations and I need fast rendering in Java. I've run into performance issues with Java2d in the past, so what are the fast alternatives? Is JOGL significantly faster than Java2d? 回答1: My experience with Java2D is that it can be very fast, if you follow the rules. I had an application that went from 90% CPU to less than 5% CPU just by changing a few simple things. Using large transparent PNG's is a no no, for example. A very good resource is the Java-Gaming

Canvas fillRect() not filling defined canvas

笑着哭i 提交于 2019-12-12 07:27:56
问题 I am extending a Canvas and adding it to a JFrame . I understand that AWT and Swing should not be mixed and that drawing on JPanel is preferred but i'm trying to follow a game engine tutorial and i'd like to stick to it since I got it working so far. The Canvas has minimumSize , maximumSize , and prefferedSize set to the dimensions of 550, 400 . When I do a draw call graphics.draw(0,0,550,400) it doesn't fill the entire screen as it should. I changed the draw call to graphics.draw(0,0,560,410

How to adjust font size on image resize? [duplicate]

妖精的绣舞 提交于 2019-12-12 06:59:06
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to edit a text that is converted into image? or any other approach to realize/edit text What I am trying to achieve is that... I have a text in textpane which I am converting to BufferedImage and resizing the size of the image by dragging it with mouse. Now If I want to edit the text, I am clicking on the image which hides the image and shows the text from textpane. My problem is the size of the text in

Add image to panel not using swings [closed]

余生颓废 提交于 2019-12-12 06:46:12
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . how to we add bitmap image in panel and then get the graphics that the image is using and tell the panel to draw a line using the same graphics inside the image. 回答1: Basic painting is done by a Swing components

Drawing a diamond with Polygon on the end of a Line2D

别说谁变了你拦得住时间么 提交于 2019-12-12 06:36:38
问题 I'm trying to draw a diamond (for a composition UML relationship). Right now, I am making a triangle like this: but I want to make something like this: And I do the triangle with this code: private void drawArrowHead(Graphics2D g2, Point tip, Point tail, Color color) { g2.setPaint(color); double dy = tip.y - tail.y; double dx = tip.x - tail.x; double theta = Math.atan2(dy, dx); double x, y, rho = theta + phi; Point p1 = new Point(); Point p2 = new Point(); p1.setLocation(tip.x - barb * Math