Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

15
LINES

< > BotCompany Repo | #1019437 // paintFitBackground_smooth - fit so whole screen is filled + smoothing

JavaX fragment (include)

import java.awt.geom.*;

static void paintFitBackground_smooth(Component c, Graphics _g, BufferedImage image) {
  Graphics2D g = cast _g;
  RenderingHints hints = g.getRenderingHints();
  antiAliasOn(g);
  int w = c.getWidth(), h = c.getHeight();
  int iw = image.getWidth(), ih = image.getHeight();
  g.setColor(c.getBackground());
  g.fillRect(0, 0, w, h);
  double imgScale = max(doubleRatio(h, ih), doubleRatio(w, iw));
  double y1 = h-ih*imgScale;
  g.drawImage(scaleImage(image, imgScale), iround((w-iw*imgScale)/2), iround((h-ih*imgScale)/2), null);
  g.setRenderingHints(hints);
}

Author comment

Began life as a copy of #1016579

download  show line numbers  debug dex  old transpilations   

Travelled to 12 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019437
Snippet name: paintFitBackground_smooth - fit so whole screen is filled + smoothing
Eternal ID of this version: #1019437/5
Text MD5: 84a90ed49d4c2fccb2aa7efb56e790a9
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-06 19:37:46
Source code size: 602 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 209 / 273
Version history: 4 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1019468 - calcFitSize - calculate size for image to fit in component or similar