More scaling modes in ImageScaleMode #653
nightm4re94
started this conversation in
Old Forum
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022).
Posted: 2019-03-20 15:06:21
User: CalvinMT [] (age: 1451 days 🔥; posts: 114)
Hi!
I think it would be good to have more scaling possibilities than NORMAL and STRETCH.
Obviously, the only one I can think of is FIT and as I needed it, I made a quick code for it.
Might not be the most efficient way, but feel free to use it:
public static BufferedImage scaleToFit (BufferedImage bufferedImage, int scaledWidth, int scaledHeight) { BufferedImage result; Graphics2D g; if ((scaledWidth / bufferedImage.getWidth()) < (scaledHeight / bufferedImage.getHeight())) { result = new BufferedImage(scaledWidth, ((bufferedImage.getHeight()*scaledWidth)/bufferedImage.getWidth()), bufferedImage.getType()); g = result.createGraphics(); g.drawImage(bufferedImage, 0, 0, scaledWidth, ((bufferedImage.getHeight()*scaledWidth)/bufferedImage.getWidth()), null); } else { result = new BufferedImage(((bufferedImage.getWidth()*scaledHeight)/bufferedImage.getHeight()), scaledHeight, bufferedImage.getType()); g = result.createGraphics(); g.drawImage(bufferedImage, 0, 0, ((bufferedImage.getWidth()*scaledHeight)/bufferedImage.getHeight()), scaledHeight, null); } g.dispose(); return result; }
Beta Was this translation helpful? Give feedback.
All reactions