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

9
LINES

< > BotCompany Repo | #1019468 // calcFitSize - calculate size for image to fit in component or similar

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5006L/28K).

static Pt calcFitSize(BufferedImage image, Component c) {
  ret calcFitSize(image, c.getWidth(), c.getHeight());
}

static Pt calcFitSize(BufferedImage image, int w, int h) {
  int iw = image.getWidth(), ih = image.getHeight();
  double imgScale = max(doubleRatio(h, ih), doubleRatio(w, iw));
  ret pt(iround(iw*imgScale), iround(ih*imgScale));
}

Author comment

Began life as a copy of #1019437

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: #1019468
Snippet name: calcFitSize - calculate size for image to fit in component or similar
Eternal ID of this version: #1019468/7
Text MD5: ebe3a78507f6063752e38b38282b21c2
Transpilation MD5: 82b4e947ae140dc4febf00c4c3938df2
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-29 02:59:42
Source code size: 354 bytes / 9 lines
Pitched / IR pitched: No / No
Views / Downloads: 271 / 342
Version history: 6 change(s)
Referenced in: [show references]