Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static BufferedImage Square(BufferedImage img) {
- int w = img.getWidth();
- int h = img.getHeight();
- BufferedImage main = null;
- boolean isWidth = false;
- if (w > h) {
- main = new BufferedImage(w, w, BufferedImage.TYPE_INT_ARGB);
- isWidth = true;
- } else if (h > w) {
- main = new BufferedImage(h, h, BufferedImage.TYPE_INT_ARGB);
- isWidth = false;
- }
- Graphics g = main.getGraphics();
- {
- g.setColor(Color.white);
- g.fillRect(0, 0, main.getWidth(), main.getHeight());
- int x = 0, y = 0;
- if (isWidth) {
- g.drawImage(img, x, (main.getHeight()/2) - (img.getHeight()/2), null);
- } else {
- g.drawImage(img, (main.getWidth()/2) - (img.getWidth()/2), y, null);
- }
- }
- g.dispose();
- return main;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement