Swing:调整图像大小但保持相同的大小 [英] Swing: resize Image but keep same size

查看:104
本文介绍了Swing:调整图像大小但保持相同的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够做类似于在gimp中调整画布大小的内容

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.

我用过

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)

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)

问题是

我有和图片A
我想创建B,C和D,如图中的图形,遵循跟随比率
B = A
C = 2/3 A
D = 1/3 A

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

但图像保持相同的维度A = B = C = D

but the image stays the same dimension A = B = C = D

推荐答案

假设我正在关注你想要做的事情......

Assuming I'm following what you are trying to do...

为每张图片创建一个JLabel:

Create a JLabel for each image:

JLable l = new JLabel(miniture);

使用GridLayout创建一个JLabel:

Create a JLabel with a GridLayout:

JPanel p = new JPanel(new GridLayout());

将标签添加到面板:

p.add(l);

GridLayout将确保所有JLabel具有相同的高度和宽度。

The GridLayout will ensure that all the JLabels will have the same height and width.

这篇关于Swing:调整图像大小但保持相同的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆