Libraryless. Compilation Failed (9824L/55K).
1 | srecord noeq PadImageToAspectRatio(BufferedImage img, Ratio ratio, Color color) > Meta { |
2 | BufferedImage out; |
3 | |
4 | *(BufferedImage *img, double ratio, Color *color) { |
5 | this.ratio = Ratio(ratio); |
6 | } |
7 | |
8 | BufferedImage get() { |
9 | int w = img.getWidth(), h = img.getHeight(); |
10 | double actualRatio = doubleRatio(w, h); |
11 | double targetRatio = this.ratio!; |
12 | int w2 = w, h2 = h; |
13 | if (targetRatio > actualRatio) // target ratio is wider |
14 | w2 = iround(h2*targetRatio); |
15 | else |
16 | h2 = iround(w2/targetRatio); |
17 | |
18 | if (scaffolding()) printVars(+w, +h, +w2, +h2, +actualRatio, +targetRatio, ratio := this.ratio); |
19 | if (w == w2 && h == h2) ret img; |
20 | |
21 | out = isFullyTransparent(color) |
22 | ? newTransparentImage(w2, h2) |
23 | : newImage(w2, h2, color); |
24 | drawImageOnImage(img, out, (w2-w)/2, (h2-h)/2); |
25 | ret out; |
26 | } |
27 | } |
Began life as a copy of #1007278
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034776 |
Snippet name: | PadImageToAspectRatio |
Eternal ID of this version: | #1034776/9 |
Text MD5: | e5b14bd6baa0a50143a39a991645ee50 |
Transpilation MD5: | 25c145057474e99672538fd9304b9d1b |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-09-12 18:33:36 |
Source code size: | 874 bytes / 27 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 175 / 305 |
Version history: | 8 change(s) |
Referenced in: | [show references] |