Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-23-2008, 11:31 PM
Member
 
Join Date: Jan 2008
Posts: 4
dishab is on a distinguished road
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
Attached Images
File Type: jpg test.jpg (1.1 KB, 18 views)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-24-2008, 06:48 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Welcome to the Java Forums!

Hmm... seems like an environment or local issue.. I run linux and it outputs this:
Attached Images
File Type: jpg test.jpg (1.3 KB, 15 views)
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-24-2008, 06:52 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
What's your code look like? Here's what I did:
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(); } } }
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-24-2008, 10:32 AM
Member
 
Join Date: Jan 2008
Posts: 4
dishab is on a distinguished road
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!
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-24-2008, 05:44 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
This doesn't appear to be a Java issue... but I've been wrong before.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-27-2008, 12:42 AM
Member
 
Join Date: Jan 2008
Posts: 4
dishab is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-29-2008, 04:20 PM
Member
 
Join Date: Jan 2008
Posts: 4
dishab is on a distinguished road
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:
Code:
Font font = createFont(Font.TrueType, new InputStream(new File("xyz.ttf"))); font = font.deriveFont(Font.BOLD, 14); g.setFont(font);
and got waht I wanted.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Linux conflict - TrayIcon image not display in Linux Eranga Advanced Java 0 03-25-2008 06:37 AM
new member need help with linux praveena New To Java 0 01-22-2008 11:22 AM
problem with ServerSocket on Linux gabriel New To Java 1 08-07-2007 05:46 PM
eclipse in linux bbq Eclipse 1 07-04-2007 09:59 AM
Linux and java Alan Advanced Java 2 05-31-2007 03:30 PM


All times are GMT +3. The time now is 08:48 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org