Java Graphics2D绘图

由于这里画图是根据字体的基线进行定位

 

所以top,也就是最终的高度需要指定高度加上descent的高度+字的高度/2

final_Y = Y+strHeight / 2 + metrics.getDescent()

Graphics2D graphics = image.createGraphics(); 
graphics.setColor(color); 

Font font = new Font("SimHei",Font.BOLD,16); 
FontDesignMetrics metrics = FontDesignMetrics.getMetrics(font); 

int strHeight = metrics.getHeight(); 
graphics.setFont(font); 
graphics.drawString("字符串", 100,100 + strHeight / 2 + metrics.getDescent() ); }); 

graphics.dispose();
《Java Graphics2D绘图》为 九城 原创,创作不易!转载请注明出处!感谢!
文章地址:https://blog.minkse.cn/java-graphics2d%e7%bb%98%e5%9b%be/
暂无评论

发送评论 编辑评论

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇