问题
I want to be able to do something similar to resize canvas in gimp
I want to generate a bunch of images to a certain width.
I used
int width = (int)(size * fraction);
int height =(int)(size*icon.getIconHeight()/icon.getIconWidth()*fraction);
miniature = new ImageIcon(i.getScaledInstance(width, height, Image.SCALE_SMOOTH));
this goes well while I'm doing fraction 1 but I have 3 images that have the same source but are different size (1, 2/3, 1/3)
the problem is
I have and image A I want to create B, C and D such as the drawing inside respect the follow ratio B = A C = 2/3 A D = 1/3 A
but the image stays the same dimension A = B = C = D
回答1:
Assuming I'm following what you are trying to do...
Create a JLabel for each image:
JLable l = new JLabel(miniture);
Create a JLabel with a GridLayout:
JPanel p = new JPanel(new GridLayout());
Add the labels to the panel:
p.add(l);
The GridLayout will ensure that all the JLabels will have the same height and width.
来源:https://stackoverflow.com/questions/6297003/swing-resize-image-but-keep-same-size