Swing:调整图像大小但保持相同大小
我希望能够执行类似于在 gimp 中调整画布大小的操作,
我想生成一堆具有特定宽度的图像。
使用
int width = (int)(size * fraction);
int height =(int)(size*icon.getIconHeight()/icon.getIconWidth()*fraction);
miniature = new ImageIcon(i.getScaledInstance(width, height, Image.SCALE_SMOOTH));
我在做分数 1 时
这个效果很好,但我有 3 个具有相同来源但大小不同的图像(1、2/3、1/3),问题是
我有图像 A 我想创建 B、C 和 D,如里面的绘图,尊重以下比例 乙=甲 C = 2/3 A D = 1/3 A
但图像保持相同尺寸 A = B = C = D
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设我遵循您想要执行的操作...
为每个图像创建一个 JLabel:
使用 GridLayout 创建 JLabel:
将标签添加到面板:
GridLayout 将确保所有 JLabels 具有相同的高度和宽度。
Assuming I'm following what you are trying to do...
Create a JLabel for each image:
Create a JLabel with a GridLayout:
Add the labels to the panel:
The GridLayout will ensure that all the JLabels will have the same height and width.