Libraryless. Click here for Pure Java version (9737L/54K).
svoid drawCenteredText(Graphics2D g, S text, int x, int y, int w, int h, Color color) { g.setColor(color); FontMetrics fm = g.getFontMetrics(); Pt p = centerTextInRect(fm, text, rect(x, y, w, h)); g.drawString(text, p.x, p.y); } static BufferedImage drawCenteredText(BufferedImage image, S text, Color color default black()) { if (image != null) drawCenteredText(antiAliasGraphics(image), text, 0, 0, image.getWidth(), image.getHeight(), color); ret image; } static BufferedImage drawCenteredText(BufferedImage image, S text, Color color default black(), Font font) { if (image != null) { var g = antiAliasGraphics(image); if (font != null) g.setFont(font); drawCenteredText(g, text, 0, 0, image.getWidth(), image.getHeight(), color); } ret image; }
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: | 435 / 578 |
| Version history: | 8 change(s) |
| Referenced in: | [show references] |