Results 1 to 2 of 2
  1. #1
    vaskarbasak is offline Member
    Join Date
    May 2008
    Posts
    13
    Rep Power
    0

    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.

    Thanks.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. AWT drawString doesn't work on Linux
    By dishab in forum Advanced Java
    Replies: 7
    Last Post: 12-15-2010, 09:43 PM
  2. Replies: 1
    Last Post: 08-21-2009, 08:07 PM
  3. characters + strings
    By Gilgamesh in forum New To Java
    Replies: 3
    Last Post: 03-02-2008, 09:10 PM
  4. Removing characters
    By kDude in forum New To Java
    Replies: 3
    Last Post: 12-03-2007, 02:38 AM
  5. Getting all characters in a String
    By Alayna in forum New To Java
    Replies: 2
    Last Post: 05-20-2007, 11:49 AM

Posting Permissions

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