Results 1 to 8 of 8
- 01-23-2008, 10:31 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 4
- Rep Power
- 0
AWT drawString doesn't work on Linux
Hi *,
I have a little program which lets me make an image from a string and write it in a file. It works well on my XP but on my Linux server only the background pink is generated but no text (see attachment) . I also tried to set the Font but it didn't help. Any Ideas?
Hier is the code:
public static void textToImage4() throws IOException {
int width = 200, height = 135;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.pink);
g.fillRect(0, 0, width, height);
// Font font = new Font("SERIF", Font.BOLD, 18);
// g2.setFont(font);
g.setColor(Color.black);
g.drawString("test", 46 , 54);
g.dispose();
ImageIO.write(image, "jpg", new File("test.jpg"));
}
I run the program with: java -Djava.awt.headless=true ...
thanks,
dishab
- 01-24-2008, 05:48 AM #2
Welcome to the Java Forums!
Hmm... seems like an environment or local issue.. I run linux and it outputs this:Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 01-24-2008, 05:52 AM #3
What's your code look like? Here's what I did:
Java Code:public class Test { public static void textToImage4() throws IOException { int width = 200, height = 135; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); g.setColor(Color.pink); g.fillRect(0, 0, width, height); // Font font = new Font("SERIF", Font.BOLD, 18); // g2.setFont(font); g.setColor(Color.black); g.drawString("test", 46 , 54); g.dispose(); ImageIO.write(image, "jpg", new File("test.jpg")); } public static void main(String[] args) { Test t = new Test(); try { t.textToImage4(); } catch (IOException ioE) { ioE.printStackTrace(); } } }Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 01-24-2008, 09:32 AM #4
Member
- Join Date
- Jan 2008
- Posts
- 4
- Rep Power
- 0
At the moemnt there is only this piece of code:
public class PicTest {
public static void main(String[] args) throws IOException {
textToImage4();
}
public static void textToImage4() throws IOException {
// ... as already posted
}
}
When it works, I want to use it for creating captchas.
I tested it also on a solaris machine and it works as expected. Only not on my Linux Red hat!
- 01-24-2008, 04:44 PM #5
This doesn't appear to be a Java issue... but I've been wrong before.
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 01-26-2008, 11:42 PM #6
Member
- Join Date
- Jan 2008
- Posts
- 4
- Rep Power
- 0
I tried some more things but had still no success:
java -Dawt.toolkit=sun.awt.X11.XToolkit -Djava.awt.headless=true -cp . PicTest
java -Dawt.toolkit=sun.awt.motif.MToolkit -Djava.awt.headless=true -cp . PicTest
I also downloaded PJA and executed PJADemo. This program generated 3 images. Two of them are including different shapes and looking good. The third one, which should contain text, is only a white rectangle.
I have no fonts under /usr/X11R6/lib/X11/fonts/TrueTypes. Can this be the problem?
Thanks, Dishab
- 01-29-2008, 03:20 PM #7
Member
- Join Date
- Jan 2008
- Posts
- 4
- Rep Power
- 0
For those who may have a similar problem: I could solve the problem. The reason was,that I had no ttf fonts an my machine and the default jdk fonts had no glyps in them (I dont know if it was a installation failur or it is the default behavior of jdk_1.4).
So I cpoied a ttf file say xyz.ttf to my machine und loaded it dynamically:
and got waht I wanted.Java Code:Font font = createFont(Font.TrueType, new InputStream(new File("xyz.ttf"))); font = font.deriveFont(Font.BOLD, 14); g.setFont(font);
- 12-15-2010, 09:43 PM #8
Member
- Join Date
- Dec 2010
- Posts
- 1
- Rep Power
- 0
i meet same problem. drawString working on XP
not working on Oracle Unbreakable Linux (EL5.)
im using embeded java in Oracle DB.
in linux command line application "java Test" is working properly
but in linux textToImage4(); method when called from PL/SQL is not working .
drawlines ok, drawString not.
what is location of file "xyz.ttf" .
Similar Threads
-
[SOLVED] Windows Linux conflict - TrayIcon image not display in Linux
By Eranga in forum Advanced JavaReplies: 6Last Post: 04-08-2009, 04:05 AM -
new member need help with linux
By praveena in forum New To JavaReplies: 0Last Post: 01-22-2008, 10:22 AM -
problem with ServerSocket on Linux
By gabriel in forum New To JavaReplies: 1Last Post: 08-07-2007, 04:46 PM -
eclipse in linux
By bbq in forum EclipseReplies: 1Last Post: 07-04-2007, 08:59 AM -
Linux and java
By Alan in forum Advanced JavaReplies: 2Last Post: 05-31-2007, 02:30 PM


LinkBack URL
About LinkBacks

Bookmarks