SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question drawString with Chinese Characters

    Hi all,
    I am trying to display a Chinese string (UTF-8) with
    Graphics2D.drawString() but nothing is displayed.
    here i paste my code

    package com;

    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;

    public class StringImage {

    public void drawImages(String data) {
    try {
    byte[] utf8 = data.getBytes("UTF-8");
    data = new String(utf8);
    BufferedImage bufferedImage = new BufferedImage(200, 200,
    BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bufferedImage.createGraphics();
    g .setColor( Color.WHITE );
    g .fillRect(0,0,200,200);
    g.setColor(Color.black);
    g.drawString(data, 20, 20);
    g.dispose();
    ImageIO.write(bufferedImage, "JPG", new File("test2.jpg"));
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    public static void main(String args[]) {
    new StringImage().drawImages("埔里鎮育英街175巷12弄7號");
    }

    }

    Please help me.

    Thanks.
    vaskar

  2. #2
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IN the line
    new StringImage().drawImages("埔里鎮育英街175巷12弄7號");

    try using the uni-code character instead of the characters it self.
    \u0123 etc...
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.

  3. #3
    SiteP0int Weazle hooknc's Avatar
    Join Date
    Dec 2004
    Location
    Socialist Republic of Boulder
    Posts
    937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Either way really should work.

    Do you have a Chinese font installed on your machine? I can actually see the correct characters above on this web page, but when I try the code on my machine I see a bunch of 'A hats' and other characters.
    baby steps... baby steps...

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also I am facing same problem.

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This brings me to an interesting question. I have a project catering for Chinese speakers based in the UK who will largely be using public, University owned machines. This means that these machines will not have Chinese characters on by default.

    Has anyone considered using sIFR to circumvent such a problem - would using such a technique on body text cause any noticable lag?
    Last edited by r937; Aug 11, 2008 at 13:17.

  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Urbane Blinds View Post
    Has anyone considered using sIFR to circumvent such a problem - would using such a technique on body text cause any noticable lag?
    I tried this out last night, and the answer is, unforunately, yes - lots of lag. Certainly enough to render such an approach a no-go.

    Does anyone know of a potential solution?

    Gracias.
    Find first class made to measure blinds at Urbane Blinds!

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Melbourne, VIC, AU
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Urbane Blinds View Post
    Has anyone considered using sIFR to circumvent such a problem - would using such a technique on body text cause any noticable lag?
    Having attempted to use sIFR on a chinese page i can say that the results are even worse. You end up having massive flash files (traditional chinese is around 20k characters) and even then you have to ensure you get the page encoding correct to start with....

    When i was a uni, plenty of foreign students would surf asian sites that contained full character sets, so maybe look at some of these sites to see how they are encoded?

    W2ttsy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •