1 | import java.awt.geom.*; |
2 | |
3 | static void paintFitBackground(Component c, Graphics _g, BufferedImage image) { |
4 | Graphics2D g = cast _g; |
5 | RenderingHints hints = g.getRenderingHints(); |
6 | antiAliasOn(g); |
7 | int w = c.getWidth(), h = c.getHeight(); |
8 | g.setColor(c.getBackground()); |
9 | g.fillRect(0, 0, w, h); |
10 | if (image != null) { |
11 | int iw = image.getWidth(), ih = image.getHeight(); |
12 | double imgScale = max(doubleRatio(h, ih), doubleRatio(w, iw)); |
13 | AffineTransform before = g.getTransform(); |
14 | double y1 = h-ih*imgScale; |
15 | g.scale(imgScale, imgScale); |
16 | g.translate(iround((w-iw*imgScale)/2), iround((h-ih*imgScale)/2)); |
17 | g.drawImage(image, 0, 0, c); |
18 | g.setTransform(before); |
19 | } |
20 | g.setRenderingHints(hints); |
21 | } |
Began life as a copy of #1015864
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1016579 |
Snippet name: | paintFitBackground - fit so whole screen is filled |
Eternal ID of this version: | #1016579/4 |
Text MD5: | e48f645a23ad682580bc41e968133e46 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-11-28 15:22:17 |
Source code size: | 742 bytes / 21 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 339 / 388 |
Version history: | 3 change(s) |
Referenced in: | [show references] |