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
6 6098
It works fine for me; btw, you can remove the following two lines because they
don't do anything, i.e. they convert a String to a String: -
byte[] utf8 = data.getBytes("UTF-8");
-
data = new String(utf8);
-
kind regards,
Jos
By the way, it's always a good idea to check the return value of ImageIO.write to see if it was successful. - boolean success = ImageIO.write(bufferedImage, "jpeg", file);
You will want to select a font, one that has the glyphs you need.
You will want to select a font, one that has the glyphs you need.
My installation is a default Java SE 1.6 with a Dialog font family used and is
perfectly well capable of running (and displaying) those foreign characters
(on an ordinary vista laptop, US locale).
kind regards,
Jos
My installation is a default Java SE 1.6 with a Dialog font family used and is
perfectly well capable of running (and displaying) those foreign characters
(on an ordinary vista laptop, US locale).
kind regards,
Jos
Call me paranoid, but I'm having doubts about the OP's setup. To test if a font can display a string, they can use Font's canDisplayUpTo.
Call me paranoid, but I'm having doubts about the OP's setup. To test if a font can display a string, they can use Font's canDisplayUpTo.
Same here; if I recall correctly there are only two Java SE downloads and I just
tried it on an CJK installation: no problem there either. It could be a funny
default bytes to chars conversion though (see my first reply about those two lines).
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jeff |
last post by:
Having a problem displaying both german and chinese characters from a
UTF-8 database on the same *.jsp page.
Can make Chinese characters appear correctly by including the following
lines:
<%@...
|
by: Zhang Weiwu |
last post by:
Hello. I am working with a php software project, in it
(www.egroupware.org) Chinese simplified locate is "zh" while Traditional
Chinese "tw".
I wish to send correct language attribute in http...
|
by: Agnes |
last post by:
In my .net ,i need to generate an xml file , however, user may input a
chinese character, Then , the xml will got something unknow characters. the
following is my code, Does anyone know how to...
|
by: pabv |
last post by:
Hello all,
I am having a few issues with encoding to chinese characters and
perhaps someone might be able to assist.
At the moment I am only able to see chinese characters when displayed
as...
|
by: K |
last post by:
I've an XML file in UTF-8.
It contains some chinese characters ( both simplified chinese and
traditional chinese).
In loading the XML file with MSXML parser, I used the below code to retrieve...
|
by: st.frey |
last post by:
I've got a problem with importing chinese characters into a mysql-table
and have read several mailings but didn't find a solution.
i have a utf-8 text file that contains chinese characters. the...
|
by: Figmo |
last post by:
I'm having a problem working with foreign characters (well....foreign
to me anyway)
I have a textbox control on a form. The font is set to MS Arial
Unicode. If I use the Chinese input method...
|
by: Wassy |
last post by:
Hi, i have a website which contains both chinese and english content
which is stored in a database. Each record in the dB has an english
and Chinese field. If a user enters a search string i have...
|
by: Flying Kite |
last post by:
Hi All,
I want to know how to print chinese characters on Zebra Printer, following code working fine with English string, but it's not working for Chinese string. It shows ASCII characters instead...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |