Hi all,
I am trying to display a Chinese string (UTF-8) with
Graphics2D.draw String() 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(Stri ng data) {
try {
byte[] utf8 = data.getBytes(" UTF-8");
data = new String(utf8);
BufferedImage bufferedImage = new BufferedImage(2 00, 200,
BufferedImage.T YPE_INT_RGB);
Graphics2D g = bufferedImage.c reateGraphics() ;
g .setColor( Color.WHITE );
g .fillRect(0,0,2 00,200);
g.setColor(Colo r.black);
g.drawString(da ta, 20, 20);
g.dispose();
ImageIO.write(b ufferedImage, "JPG", new File("test2.jpg "));
} catch (Exception e) {
e.printStackTra ce();
}
}
public static void main(String args[]) {
new StringImage().d rawImages("埔里鎮育 英街175巷12弄 7號");
}
}
Please help me.
Thanks.
vaskar
I am trying to display a Chinese string (UTF-8) with
Graphics2D.draw String() 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(Stri ng data) {
try {
byte[] utf8 = data.getBytes(" UTF-8");
data = new String(utf8);
BufferedImage bufferedImage = new BufferedImage(2 00, 200,
BufferedImage.T YPE_INT_RGB);
Graphics2D g = bufferedImage.c reateGraphics() ;
g .setColor( Color.WHITE );
g .fillRect(0,0,2 00,200);
g.setColor(Colo r.black);
g.drawString(da ta, 20, 20);
g.dispose();
ImageIO.write(b ufferedImage, "JPG", new File("test2.jpg "));
} catch (Exception e) {
e.printStackTra ce();
}
}
public static void main(String args[]) {
new StringImage().d rawImages("埔里鎮育 英街175巷12弄 7號");
}
}
Please help me.
Thanks.
vaskar
Comment