Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ezhov-da/38112731e22a2c5fc9410797eb3b81fb to your computer and use it in GitHub Desktop.
Save ezhov-da/38112731e22a2c5fc9410797eb3b81fb to your computer and use it in GitHub Desktop.
размер изображения как в компоненте
/**
* 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