Libraryless. Click here for Pure Java version (9737L/54K).
1 | svoid drawCenteredText(Graphics2D g, S text, int x, int y, int w, int h, Color color) { |
2 | g.setColor(color); |
3 | FontMetrics fm = g.getFontMetrics(); |
4 | Pt p = centerTextInRect(fm, text, rect(x, y, w, h)); |
5 | g.drawString(text, p.x, p.y); |
6 | } |
7 | |
8 | static BufferedImage drawCenteredText(BufferedImage image, S text, Color color default black()) { |
9 | if (image != null) |
10 | drawCenteredText(antiAliasGraphics(image), text, 0, 0, image.getWidth(), image.getHeight(), color); |
11 | ret image; |
12 | } |
13 | |
14 | static BufferedImage drawCenteredText(BufferedImage image, S text, Color color default black(), Font font) { |
15 | if (image != null) { |
16 | var g = antiAliasGraphics(image); |
17 | if (font != null) |
18 | g.setFont(font); |
19 | drawCenteredText(g, text, 0, 0, image.getWidth(), image.getHeight(), color); |
20 | } |
21 | ret image; |
22 | } |
Began life as a copy of #1031118
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031119 |
Snippet name: | drawCenteredText |
Eternal ID of this version: | #1031119/9 |
Text MD5: | 796e56306972d001e492227f451f5e9b |
Transpilation MD5: | 56a3cdddd9811961fc1df4050ad598a6 |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-11-27 02:36:01 |
Source code size: | 812 bytes / 22 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 180 / 278 |
Version history: | 8 change(s) |
Referenced in: | [show references] |