Libraryless. Click here for Pure Java version (5805L/32K).
srecord FitImageInComponentRenderable(BufferedImage srcImage) is Renderable { settable Color backgroundColor = Color.white; public void renderOn(Graphics2D g, int w, int h) { if (backgroundColor != null) { g.setColor(Color.white); g.fillRect(0, 0, w, h); } if (srcImage == null) ret; double scale = scaleToFitInside(srcImage, w, h); int x = (w-iround(srcImage.getWidth()*scale))/2; int y = (h-iround(srcImage.getHeight()*scale))/2; g.translate(x, y); g.scale(scale, scale); g.drawImage(srcImage, 0, 0, null); } }
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034405 |
Snippet name: | FitImageInComponentRenderable |
Eternal ID of this version: | #1034405/7 |
Text MD5: | 6fa7e078f9a360c4717ad674669eee4a |
Transpilation MD5: | 52bd42a1645ed3a8d3eff19794cd9295 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-05 23:52:20 |
Source code size: | 591 bytes / 18 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 166 / 262 |
Version history: | 6 change(s) |
Referenced in: | [show references] |