![]() |
| ||
| Trying to draw text at an angle I want to draw some text on a JFrame (later it'll change to a JPanel), but not have the text necessarily be horizontal. I've found some decent examples online that have worked well, but they've all been 500+ lines long. I'm hoping it can be done in a way that's shorter. My understanding is that I can't use plain old drawStringdirectly onto the JFrame if I don't want the text to be horizontal. Instead I need to create an image, then tilt the image, then draw the image onto the the JFrame. My attempt so far creates an image and draws it onto the JFrame, but it's horizontal. Does anyone know a way to tilt the image to get sideways text or how to get sideways text some other way that doesn't require several hundred more lines of code? I'm pretty much of a noob when it comes to images. Thanks. Here's my attempt so far that makes the text horizontal. import javax.swing.*; |
| ||
| Re: Trying to draw text at an angle a search i did i found this: public static BufferedImage rotate(Image image, double angle, int cx, int cy){it rotates an entire image, so you could make an image write a line on it and pass it to this method, it's likely to be slow, i don't know much about afflinetransform |
| ||
| Re: Trying to draw text at an angle Quote:
|
| ||
| Re: Trying to draw text at an angle Do you want to draw an image from a file, or do you want to be able to "rotate" a set of pixels such that they emulate a rotating String? This can be either really simple or hard depending on where you want to rotate. If you have variable rotation points, this sill be incredibly hard. |
| ||
| Re: Trying to draw text at an angle i didn't notice it had these calls... i'll write a method like this myself, that doesn't use afflinetransform.. but it will be slow, i should be able to post one before midnight, but likely in the next hour. |
| ||
| Re: Trying to draw text at an angle Quote:
|
| ||
| Re: Trying to draw text at an angle Quote:
Cool, right on. Thank you. I'm not familiar enough yet with what is required and what transformations are needed, so I don't know what a fast method is or a slow method. Maybe I'll have to solve it first with a slow solution, then optimize. I've seen a lot of Java applets with spinning text, so it's definitely been done many times, but I've never had occasion till now to investigate how to do it. Thanks again. |
| ||
| Re: Trying to draw text at an angle ok, I wrote these two classes CustomPane is the one that has the rotateImage() method. //CustomPane.java //RotateText.java this example is of an animated rotating sentence, as i said this method is very slow, and inaccurate i hope that it is clear what i did. mostly basic trig. |
| ||
| Re: Trying to draw text at an angle Quote:
Hey thanks! I think I get he idea a little better now. I've changed the math to make the calculation a bit faster, but the idea is the same. You have a pixel that is at location (x1,y1) at angle 1 and you have to find the corresponding (x2, y2) point at angle 2 that corresponds to it. It's not a completely brute force method, but I'm still assigning a color to the buffered image on a pixel by pixel basis. I wonder whether there's a way where you don't have to go pixel by pixel like that? I've been getting decent results except sometimes for no obvious reason, I'm getting little dots in my letters instead of nice contiguous color patterns. The characters tend to look the best when they are close to horizontal or close to vertical. I'm thinking I've got some slight round-off error. But I'm a lot more on the right track now, so thank you again! |
| ||
| Re: Trying to draw text at an angle yes, the blurry text is because of int rounding error. a better way to do it would be affinetransform, but i haven't used it much, and the sun tutorial confused me a bit, i think that this may also help. |
| All times are GMT -4. The time now is 10:41 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC