How to resize an image or iimage?
1 post
• Page 1 of 1
Re: How to resize an image or iimage?
The UIIcon does support to set the alignment to STRETCH which will fit the image to the bounds of the component. Additionally it supports to preserve the aspect ratio to make sure that the image is not distorted. If you want an UIIcon to be a certain size you can set the preferred size of the component:
This will make the UIIcon component to display the image as big as it is (with correct aspect ratio) and also the component will have a size of 800x600. Obviously, whether the preferred size is actually honored or not is dependent on the layout that is used. The UIBorderLayout for example does only honor parts of the set preferred size, or none at all, neither does the UIGridLayout. The other layouts (UIFormLayout, UIFlowLayout) do honor the preferred size (if applicable).
If you actually want to resize an image, there is the ImageUtil which allows you to do that.
- Code: Select all
UIIcon icon = new UIIcon(image);
icon.setHorizontalAlignment(UIIcon.ALIGN_STRETCH);
icon.setVerticalAlignment(UIIcon.ALIGN_STRETCH);
icon.setPreserveAspectRatio(true);
icon.setPreferredSize(800, 600);
This will make the UIIcon component to display the image as big as it is (with correct aspect ratio) and also the component will have a size of 800x600. Obviously, whether the preferred size is actually honored or not is dependent on the layout that is used. The UIBorderLayout for example does only honor parts of the set preferred size, or none at all, neither does the UIGridLayout. The other layouts (UIFormLayout, UIFlowLayout) do honor the preferred size (if applicable).
If you actually want to resize an image, there is the ImageUtil which allows you to do that.
-
rzenz - Posts: 36
- Joined: Mon Dec 12, 2016 1:40 pm
- Location: Vienna, Austria
1 post
• Page 1 of 1