一个使用Graphics2D的奇怪的问题----- 急,帮忙解决给500分

overcast 2002-01-24 11:38:19
我用Graphics2D类输出文字的时候用了rotate将画笔旋转
来使得可以画出旋转的字
但是为什么画了几次之后发现消耗了很多的内存
我用任务管理器看的时候有100多M
请问这是为什么阿
不旋转是没有问题的阿

还有我设置了-mx100m上限运行的时候居然没有溢出
但是务管理器看的时候已经有108M了阿
请问这是怎么回事啊
...全文
117 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
overcast 2002-01-24
  • 打赏
  • 举报
回复
没有,只是在一个函数中用for循环显示旋转的文字
估计也就100-200次吧
skyyoung 2002-01-24
  • 打赏
  • 举报
回复
看你代码是否创建了很多对象!?
山卜居士 2002-01-24
  • 打赏
  • 举报
回复
这是我写的旋转文字的方法:

public void rotateText(Graphics g, String s, double angle, int x, int y)
{
Graphics2D g2d = (Graphics2D)g;

// Move the origin to the (x,y)
g2d.translate(x, y);
// Rotate the angle
g2d.rotate(Math.PI*(angle/-180));
// Draw text
g2d.drawString(s, 0, 0);
//Restore moving and rotating
g2d.rotate(-Math.PI*(angle/-180));
g2d.translate(-x,-y);
}
overcast 2002-01-24
  • 打赏
  • 举报
回复
我刚才试了第一位老兄的程序
还是有问题
不过如果我在循环体内加上一条比如System.out,println(s);
运行的时候就很慢
但是在资源管理器中看只用了22多M内存
去掉的话,用了60多M
我的循环是400多次
public void rotateText(Graphics g, String s, double angle, int x, int y)
{
Graphics2D g2d = (Graphics2D)g;

// Move the origin to the (x,y)
g2d.translate(x, y);
// Rotate the angle
g2d.rotate(Math.PI*(angle/-180));
~~~~~~~~~~~~~~~~~~这个地方应该是-Math.PI*angle/180;
// Draw text
g2d.drawString(s, 0, 0);
//Restore moving and rotating
g2d.rotate(-Math.PI*(angle/-180));
g2d.translate(-x,-y);
}
czb 2002-01-24
  • 打赏
  • 举报
回复
试下g2d.dispose()

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧