如何在java netbeans IDE 8.1中将图像集调整为图标大小

时间:2016-08-28 15:12:15

标签: java netbeans

我是Java的新手,我已经学会了如何在jLabel中添加netbeans中的图像作为图标type WINHTTP_PROXY_INFO = record AccessType: Cardinal; Proxy: Cardinal; ProxyBypass: Cardinal; end; function WinHttpGetDefaultProxyConfiguration(var ProxyInfo: WINHTTP_PROXY_INFO): Boolean; external 'WinHttpGetDefaultProxyConfiguration@winhttp.dll stdcall'; function StrCpyN(S1: string; S2: Cardinal; Max: Cardinal): Cardinal; external 'StrCpyNW@shlwapi.dll stdcall'; function GetProxy: string; var ProxyInfo: WINHTTP_PROXY_INFO; begin if WinHttpGetDefaultProxyConfiguration(ProxyInfo) then begin SetLength(Result, 1024); StrCpyN(Result, ProxyInfo.Proxy, Length(Result) - 1); Result := Trim(Result); Log('Retrieved proxy information: ' + Result); end else begin Log('Cannot retrieve proxy information'); end; end; ,但图像以臭名昭着的方式行事,因为它变得太大了这种方式只能看到它的一部分。

我尝试了各种各样的方法,但我没有解决,大多数答案通过编码来解释,这是我不熟悉的方式。

因此,我谦虚地寻求帮助,了解如何使该图像适合小型jLabel,或者是否有其他方法可以实现此目的。 (这些图像适用于具有图像复选框和名称的计算机投票系统。)

1 个答案:

答案 0 :(得分:2)

您可以在IDE中调整图像大小...

enter image description here

或在SourceCode中:

BufferedImage img;
try {
    img = ImageIO.read(new File("strawberry.jpg"));
} catch (IOException e) {
    e.printStackTrace();
}

BufferedImage dimg = img.getScaledInstance(64, 64,        Image.SCALE_SMOOTH);

ImageIcon imageIcon = new ImageIcon(dimg);