本文整理了Java中java.awt.Image.getScaledInstance()
方法的一些代码示例,展示了Image.getScaledInstance()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Image.getScaledInstance()
方法的具体详情如下:
包路径:java.awt.Image
类名称:Image
方法名:getScaledInstance
[英]Creates a scaled version of this image. A new Image
object is returned which will render the image at the specified width
and height
by default. The new Image
object may be loaded asynchronously even if the original source image has already been loaded completely. If either the width
or height
is a negative number then a value is substituted to maintain the aspect ratio of the original image dimensions.
[中]创建此图像的缩放版本。将返回一个新的Image
对象,默认情况下,该对象将在指定的width
和height
位置渲染图像。即使原始源映像已完全加载,也可以异步加载新的Image
对象。如果width
或height
为负数,则替换一个值以保持原始图像尺寸的纵横比。
代码示例来源:origin: stackoverflow.com
Image img = icon.getImage() ;
Image newimg = img.getScaledInstance( NEW_WIDTH, NEW_HEIGHT, java.awt.Image.SCALE_SMOOTH ) ;
icon = new ImageIcon( newimg );
代码示例来源:origin: bonnyfone/vectalign
private void initIcons() {
icnPlay = new ImageIcon((new ImageIcon(this.getClass().getResource("/icn_play.png")).getImage().getScaledInstance(btnIconSize, btnIconSize, java.awt.Image.SCALE_SMOOTH)));
icnPause = new ImageIcon((new ImageIcon(this.getClass().getResource("/icn_pause.png")).getImage().getScaledInstance(btnIconSize, btnIconSize, java.awt.Image.SCALE_SMOOTH)));
icnCopy = new ImageIcon((new ImageIcon(this.getClass().getResource("/icn_copy.png")).getImage().getScaledInstance(btnIconSize, btnIconSize, java.awt.Image.SCALE_SMOOTH)));
icnExport = new ImageIcon((new ImageIcon(this.getClass().getResource("/export-icon.png")).getImage().getScaledInstance(btnIconSize, btnIconSize, java.awt.Image.SCALE_SMOOTH)));
}
代码示例来源:origin: stackoverflow.com
ImageIcon imageIcon = new ImageIcon("./img/imageName.png"); // load the image to a imageIcon
Image image = imageIcon.getImage(); // transform it
Image newimg = image.getScaledInstance(120, 120, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
imageIcon = new ImageIcon(newimg); // transform it back
代码示例来源:origin: bonnyfone/vectalign
checkVectorCompat = new JCheckBox("include vector-compat attributes", lastSupportVectorCompat);
btnExport = new JButton("Export", new ImageIcon((new ImageIcon(this.getClass().getResource("/export-icon.png")).getImage().getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH))));
btnOpenDir = new JButton("...");
代码示例来源:origin: stackoverflow.com
new JLabel(
new ImageIcon(
img.getScaledInstance(
img.getWidth(null)/2,
img.getHeight(null)/2,
代码示例来源:origin: 4thline/cling
setIcon(new ImageIcon(rootDeviceIcon.getImage().getScaledInstance(24, 24, java.awt.Image.SCALE_SMOOTH)));
} else {
setIcon(Application.createImageIcon(Workbench.class, "img/24/device.png"));
代码示例来源:origin: magefree/mage
protected static Image getImageFromResourceTransparent(String path, Color mask, Rectangle rec) {
BufferedImage image;
Image imageCardTransparent;
Image resized = null;
URL imageURL = ImageManager.class.getResource(path);
try {
image = ImageIO.read(imageURL);
imageCardTransparent = Transparency.makeColorTransparent(image, mask);
resized = imageCardTransparent.getScaledInstance(rec.width, rec.height, java.awt.Image.SCALE_SMOOTH);
} catch (Exception e) {
e.printStackTrace();
}
return resized;
}
代码示例来源:origin: magefree/mage
public MageScrollButton(int direction, int width, boolean freeStanding) {
super(direction, width, freeStanding);
setOpaque(false);
this.width = width;
buttonUp.setImage(buttonUp.getImage().getScaledInstance(width, width, Image.SCALE_SMOOTH));
buttonDown.setImage(buttonDown.getImage().getScaledInstance(width, width, Image.SCALE_SMOOTH));
buttonLeft.setImage(buttonLeft.getImage().getScaledInstance(width, width, Image.SCALE_SMOOTH));
buttonRight.setImage(buttonRight.getImage().getScaledInstance(width, width, Image.SCALE_SMOOTH));
}
代码示例来源:origin: stackoverflow.com
test.add(new JLabel(new ImageIcon((new ImageIcon("image.jpg")).getImage().getScaledInstance(630, 600,
java.awt.Image.SCALE_SMOOTH))));
代码示例来源:origin: SeanDragon/protools
Image outputImage = inputImage.getScaledInstance(width, height, Image.SCALE_DEFAULT);
checkImage(outputImage);
encode(new FileOutputStream(resizedFile), outputImage, format);
代码示例来源:origin: magefree/mage
Image newimg = img.getScaledInstance(GUISizeHelper.menuFont.getSize(), GUISizeHelper.menuFont.getSize(), java.awt.Image.SCALE_SMOOTH);
btnStateWaiting.setIcon(new ImageIcon(newimg));
newimg = img.getScaledInstance(GUISizeHelper.menuFont.getSize(), GUISizeHelper.menuFont.getSize(), java.awt.Image.SCALE_SMOOTH);
btnStateActive.setIcon(new ImageIcon(newimg));
newimg = img.getScaledInstance(GUISizeHelper.menuFont.getSize(), GUISizeHelper.menuFont.getSize(), java.awt.Image.SCALE_SMOOTH);
btnStateFinished.setIcon(new ImageIcon(newimg));
icon = new javax.swing.ImageIcon(getClass().getResource("/buttons/match_new.png"));
img = icon.getImage();
newimg = img.getScaledInstance(iconSize, iconSize, java.awt.Image.SCALE_SMOOTH);
btnNewTable.setIcon(new ImageIcon(newimg));
newimg = img.getScaledInstance(iconSize, iconSize, java.awt.Image.SCALE_SMOOTH);
btnNewTournament.setIcon(new ImageIcon(newimg));
代码示例来源:origin: SeanDragon/protools
int iHeight = i.getHeight(null);
if (iWidth > iHeight) {
resizedImage = i.getScaledInstance(newWidth, (newWidth * iHeight) / iWidth, Image.SCALE_SMOOTH);
} else {
resizedImage = i.getScaledInstance((newWidth * iWidth) / iHeight, newWidth, Image.SCALE_SMOOTH);
代码示例来源:origin: haraldk/TwelveMonkeys
public static Image fakeSubsampling(final Image pImage, final IIOParam pParam) {
if (pImage == null) {
return null;
}
if (pParam != null) {
int x = pParam.getSourceXSubsampling();
int y = pParam.getSourceYSubsampling();
// 1 is default
if (x > 1 || y > 1) {
int w = (ImageUtil.getWidth(pImage) + x - 1) / x;
int h = (ImageUtil.getHeight(pImage) + y - 1) / y;
// Fake subsampling by scaling fast
return pImage.getScaledInstance(w, h, Image.SCALE_FAST);
}
}
return pImage;
}
代码示例来源:origin: stackoverflow.com
int x2 = rectLocale.x - ((width2 - rectSize.width) / 2);
int y2 = rectLocale.y - ((height2 - rectSize.height) / 2);
Image scaledInstance = capture.getScaledInstance(
width2, height2, Image.SCALE_AREA_AVERAGING);
g2d.drawImage(scaledInstance, x2, y2, null);
代码示例来源:origin: stackoverflow.com
size.height = -1;
Image scaled = master.getScaledInstance(size.width, size.height, java.awt.Image.SCALE_SMOOTH);
btn.setIcon(new ImageIcon(scaled));
代码示例来源:origin: stackoverflow.com
img = ImageIO.read(new URL("http://images4.wikia.nocookie.net/__cb20120515073660/naruto/images/0/09/Naruto_newshot.png")).getScaledInstance(200, 200, Image.SCALE_SMOOTH);
} catch (Exception ex) {
ex.printStackTrace();
代码示例来源:origin: bobbylight/RSyntaxTextArea
if (master!=null) {
do {
Image i = master.getScaledInstance(width,height, hint);
tracker.addImage(i, 1);
try {
代码示例来源:origin: igniterealtime/Spark
public void setIcon(Icon icon) {
if (icon.getIconHeight() > 64 || icon.getIconWidth() > 64) {
Image image = ImageCombiner.iconToImage(icon);
label.setIcon(new ImageIcon(image.getScaledInstance(-1, 64, Image.SCALE_SMOOTH)));
} else
{
label.setIcon(icon);
}
}
代码示例来源:origin: SKCraft/Launcher
public static Icon createIcon(Class<?> clazz, String name, int width, int height) {
Image image = createImage(clazz, name);
if (image != null) {
return new ImageIcon(image.getScaledInstance(width, height, Image.SCALE_SMOOTH));
} else {
return new EmptyIcon(width, height);
}
}
代码示例来源:origin: datacleaner/DataCleaner
public Image scale(Image image) {
if (image == null || getSizeAdjustment() == 1f) {
return image;
}
final int w = image.getWidth(null);
final int h = image.getHeight(null);
return image.getScaledInstance(adjust(w), adjust(h), Image.SCALE_SMOOTH);
}
}
内容来源于网络,如有侵权,请联系作者删除!