简体   繁体   English

Swing:调整图像大小但保持相同大小

[英]Swing: resize Image but keep same size

I want to be able to do something similar to resize canvas in gimp我希望能够在 gimp 中做类似调整 canvas 的事情

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)这在我做分数 1 时很顺利,但我有 3 张图像具有相同的来源但大小不同(1、2/3、1/3)

the problem is问题是

I have and image AI want to create B, C and D such as the drawing inside respect the follow ratio B = A C = 2/3 AD = 1/3 A我有和图像AI要创建B,C和D如里面的绘图尊重跟随比率B = A C = 2/3 AD = 1/3 A

but the image stays the same dimension A = B = C = D但图像保持相同的尺寸 A = B = C = D

Assuming I'm following what you are trying to do...假设我正在关注你正在尝试做的事情......

Create a JLabel for each image:为每个图像创建一个 JLabel:

JLable l = new JLabel(miniture);

Create a JLabel with a GridLayout:创建一个带有 GridLayout 的 JLabel:

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. GridLayout 将确保所有 JLabel 具有相同的高度和宽度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM