Topic: 求教:在Java2D中如何实现文字以竖排的方式画在画布上?

  Print this page

1.求教:在Java2D中如何实现文字以竖排的方式画在画布上? Copy to clipboard
Posted by: sportscar
Posted on: 2004-10-18 14:26

用TextLayout文字只能以横排方式打印,怎样才能实现竖排打印呢?

BufferedImage image = new BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB );
Graphics2D g2=(Graphics2D) image.getGraphics();

FontRenderContext frc = g2.getFontRenderContext();

Font f = new Font("黑体", Font.BOLD,40);
TextLayout tl = new TextLayout(msg, f, frc);

float sw1 = (float) tl.getBounds().getWidth();
float sh1 = (float) tl.getBounds().getHeight();
Shape sha1 = tl.getOutline(AffineTransform.getTranslateInstance(WIDTH/2.0-sw1/2.0,HEIGHT/2.0+sh1/2.0));

g2.setColor(Color.red);
g2.fill(sha1);
g2.dispose();
return image;


请指教,谢谢!

2.Re:求教:在Java2D中如何实现文字以竖排的方式画在画布上? [Re: sportscar] Copy to clipboard
Posted by: ljy0000
Posted on: 2004-10-18 15:21

protected void paintComponent(Graphics g)
{
super.paintComponentPresent;
Dimension dimension = getSize();
Graphics2D g2=(Graphics2D) g;
g2.rotate(Math.PI/2,dimension.width / 2, dimension.height / 2);
g2.drawString(string, dimension.width / 2, dimension.height / 2);

}

3.Re:求教:在Java2D中如何实现文字以竖排的方式画在画布上? [Re: sportscar] Copy to clipboard
Posted by: sportscar
Posted on: 2004-10-18 15:52

谢谢您,
我想要的是如“安定门“这样的竖排方式,而不是“建国门”这样的方式,讲讲思路也行啊

4.Re:求教:在Java2D中如何实现文字以竖排的方式画在画布上? [Re: sportscar] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-18 22:05

一般是取得单个字的高和宽,然后循环进行绘制,其间需要注意和修改绘制的位置


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923