Last active
March 10, 2019 12:16
-
-
Save ezhov-da/38112731e22a2c5fc9410797eb3b81fb to your computer and use it in GitHub Desktop.
размер изображения как в компоненте
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Resizes image to panel's width and height. | |
* @param img Source image. | |
* @param panel Panel with new sizes. | |
* @return resized image. | |
*/ | |
public static BufferedImage resize(BufferedImage img, JPanel panel){ | |
Image tmp = img.getScaledInstance(panel.getWidth(), panel.getHeight(), Image.SCALE_SMOOTH); | |
img = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB); | |
Graphics2D g2d = img.createGraphics(); | |
g2d.drawImage(tmp, 0, 0, null); | |
g2d.dispose(); | |
return img; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment