finale 2014 java_Java Image.getScaledInstance方法代碼示例

本文整理匯總了Java中java.awt.Image.getScaledInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java Image.getScaledInstance方法的具體用法?Java Image.getScaledInstance怎麽用?Java Image.getScaledInstance使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Image的用法示例。

在下文中一共展示了Image.getScaledInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: getResizedImage

​點讚 3

import java.awt.Image; //導入方法依賴的package包/類

private Image getResizedImage(Image image, int newSize, int operation) {

int iWidth = image.getWidth(null);

int iHeight = image.getHeight(null);

int hints = Image.SCALE_SMOOTH;

switch (operation) {

case 1:// 按寬度縮放

return image.getScaledInstance(newSize, (newSize * iHeight) / iWidth, hints);

case 2:// 按高度縮放

return image.getScaledInstance((newSize * iWidth) / iHeight, newSize, hints);

default:// 哪邊大按哪邊縮放

if (iWidth > iHeight) {

return image.getScaledInstance(newSize, (newSize * iHeight) / iWidth, hints);

} else {

return image.getScaledInstance((newSize * iWidth) / iHeight, newSize, hints);

}

}

}

開發者ID:wooui,項目名稱:springboot-training,代碼行數:18,

示例2: resizeImage

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

/**

* Helper method used to resize input image and display it. If image was already resized to current size,

* take the copy from local cache.

*/

protected void resizeImage() {

// Resets cache if width has changed

if (currentWidth != this.getWidth()) {

currentWidth = this.getWidth();

cache.clear();

}

// If this component size is not already defined, sets image without resizing

Dimension d = this.getSize();

if (d.width <= 0 || d.height <= 0) {

this.setIcon(image);

return;

}

// If cache contains image of the correct size, returns it.

if (cache.containsKey(image)) {

this.setIcon(cache.get(image));

return;

}

// Calculates ratio factor

Image tmp = image.getImage();

float scale = (float) d.width / (float) image.getIconWidth();

if (scale * image.getIconHeight() > maxheight) {

scale = (float) maxheight / (float) image.getIconHeight();

}

// Resizes image

tmp = tmp.getScaledInstance((int) (scale * image.getIconWidth()), (int) (scale * image.getIconHeight()), Image.SCALE_SMOOTH);

ImageIcon resized = new ImageIcon(tmp);

if (cache.size() > maxCache) {

cache.clear();

}

cache.put(image, resized);

this.setIcon(resized);

}

開發者ID:max6cn,項目名稱:jmt,代碼行數:42,

示例3: loadIcon

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

/**

* Loads an icon with specified name and caches it, then resizes it.

* @param iconName name of the icon to be loaded. Extensions are automatically added, if needed.

* @param size target dimension of image. a negative number means to maintain aspect ratio on that dimension

* @return icon if found, null otherwise

*/

public ImageIcon loadIcon(String iconName, Dimension size) {

ImageIcon im = loadIcon(iconName);

if (im != null) {

Image scaled = im.getImage();

scaled = scaled.getScaledInstance(size.width, size.height, Image.SCALE_SMOOTH);

return new ImageIcon(scaled);

} else {

return im;

}

}

開發者ID:max6cn,項目名稱:jmt,代碼行數:17,

示例4: loadIcon

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

/**

* Loads an icon with specified name and caches it, then resizes it.

* @param iconName name of the icon to be loaded. Extensions are automatically added, if needed.

* @param size target dimension of image. a negative number means to mantain aspect ratio on that dimension

* @return icon if found, null otherwise

*/

public ImageIcon loadIcon(String iconName, Dimension size) {

ImageIcon im = loadIcon(iconName);

if (im != null) {

Image scaled = im.getImage();

scaled = scaled.getScaledInstance(size.width, size.height, Image.SCALE_SMOOTH);

return new ImageIcon(scaled);

} else {

return im;

}

}

開發者ID:HOMlab,項目名稱:QN-ACTR-Release,代碼行數:17,

示例5: maximizeImage

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

public void maximizeImage(boolean b)

{

if (b)

{

Image resizedImage = null;

Image img = null;

try

{

//TODO

if (currentData==null)

img = ImageIO.read(new File(Settings.imgPath + "/bt/2014/BauchbilderBa_BIL1/05_BauchbilderBa_16_05_2014_BIL/14Ba_0021.JPG"));

else

img = ImageIO.read(new File(currentData.getFileName()));

resizedImage = img.getScaledInstance(GUISettings.defaultImageCompareWidth, dph, Image.SCALE_SMOOTH);

}

catch (Exception e)

{

e.printStackTrace();

}

icon.setImage(resizedImage);

imgLabel.setPreferredSize(new Dimension(GUISettings.defaultImageCompareWidth, dph));

imgHoverEnabled = false;

this.dataPanel.setVisible(false);

}

else

{

imgHoverEnabled = true;

imgLabel.setPreferredSize(new Dimension(iw, 268));

this.dataPanel.setVisible(false);

}

this.revalidate();

this.repaint();

//this.zooPanel.setMinimumSize(new Dimension(dpw, dph));

//this.zooPanel.setPreferredSize(new Dimension(dpw, dph));

}

開發者ID:fossasia,項目名稱:zooracle,代碼行數:39,

示例6: insertImage

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

private static void insertImage(BufferedImage source, String imgPath,

boolean needCompress) throws Exception {

File file = new File(imgPath);

if (!file.exists()) {

System.err.println(""+imgPath+" 該文件不存在!");

return;

}

Image src = ImageIO.read(new File(imgPath));

int width = src.getWidth(null);

int height = src.getHeight(null);

if (needCompress) {// 壓縮LOGO

if (width > WIDTH) {

width = WIDTH;

}

if (height > HEIGHT) {

height = HEIGHT;

}

Image image = src.getScaledInstance(width, height,

Image.SCALE_SMOOTH);

BufferedImage tag = new BufferedImage(width, height,

BufferedImage.TYPE_INT_RGB);

Graphics g = tag.getGraphics();

g.drawImage(image, 0, 0, null); // 繪製縮小後的圖

g.dispose();

src = image;

}

// 插入LOGO

Graphics2D graph = source.createGraphics();

int x = (QRCODE_SIZE - width) / 2;

int y = (QRCODE_SIZE - height) / 2;

graph.drawImage(src, x, y, width, height, null);

Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);

graph.setStroke(new BasicStroke(3f));

graph.draw(shape);

graph.dispose();

}

開發者ID:Fetax,項目名稱:Fetax-AI,代碼行數:37,

示例7: scaleImage

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

/**

* Uses {@link #IMAGE_SCALING} to scale the given image.

*/

protected Image scaleImage(Image img, int w, int h)

{

Dimension size = getImageSize(img);

if (w == size.width && h == size.height)

{

return img;

}

else

{

return img.getScaledInstance(w, h, IMAGE_SCALING);

}

}

開發者ID:GDSRS,項目名稱:TrabalhoFinalEDA2,代碼行數:17,

示例8: scaleImage

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

/**

* Uses {@link #IMAGE_SCALING} to scale the given image.

*/

protected Image scaleImage(Image img, int w, int h) {

Dimension size = getImageSize(img);

if (w == size.width && h == size.height) {

return img;

} else {

return img.getScaledInstance(w, h, IMAGE_SCALING);

}

}

開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:13,

示例9: CognizantITSFileChooser

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

public CognizantITSFileChooser(Image i, String title, SelectionMode selMode, File startIn, FileFilter selector) {

super(startIn);

ICON_14 = new ImageIcon(i.getScaledInstance(13, 13, 4));

this.selector = selector;

setDialogTitle(title);

setMultiSelectionEnabled(false);

setFileSelectionMode(selMode.ordinal());

setAcceptAllFileFilterUsed(false);

if (JFileChooser.FILES_ONLY != selMode.ordinal()) {

addPropertyChangeListener((PropertyChangeListener) this);

}

}

開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:13,

示例10: main

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

public static void main(String[] args) {

Image image = new TestMultiResolutionCachedImage(100);

image.getWidth(null);

image.getHeight(null);

image.getProperty("comment", null);

int scaledSize = 50;

Image scaledImage = image.getScaledInstance(scaledSize, scaledSize,

Image.SCALE_SMOOTH);

if (!(scaledImage instanceof BufferedImage)) {

throw new RuntimeException("Wrong scaled image!");

}

BufferedImage buffScaledImage = (BufferedImage) scaledImage;

if (buffScaledImage.getWidth() != scaledSize

|| buffScaledImage.getHeight() != scaledSize) {

throw new RuntimeException("Wrong scaled image!");

}

if (buffScaledImage.getRGB(scaledSize / 2, scaledSize / 2) != TEST_COLOR.getRGB()) {

throw new RuntimeException("Wrong scaled image!");

}

}

開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,

示例11: getScaledImageIcon

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

public static ImageIcon getScaledImageIcon(String path, int w, int h) {

Image img = new ImageIcon("tmp.png").getImage();

img.flush();

int x = img.getWidth(null);

int y = img.getHeight(null);

double scale = Math.min((double) (w) / x, (double) (h) / y);

x = (int) (x * scale);

y = (int) (y * scale);

return new ImageIcon(img.getScaledInstance(x, y, Image.SCALE_SMOOTH));

}

開發者ID:xehoth,項目名稱:VisualGraphviz,代碼行數:12,

示例12: loadFromResource

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

public static ImageIcon loadFromResource(String key, boolean reescale) {

ImageIcon ic;

try {

ic = Configuer.getImageIconFromResource(key);

Image img = TratadorDeImagens.makeColorTransparent(ic.getImage(), Color.WHITE);

if (reescale) {

return new ImageIcon(img.getScaledInstance(16, 16, java.awt.Image.SCALE_SMOOTH));

}

return new ImageIcon(img);

} catch (Exception e) {

util.BrLogger.Logger("ERROR_LOAD_ICON", e.getMessage());

}

return null;

}

開發者ID:chcandido,項目名稱:brModelo,代碼行數:15,

示例13: drawImage

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

/**

*

*/

public void drawImage(Rectangle bounds, String imageUrl,

boolean preserveAspect, boolean flipH, boolean flipV)

{

if (imageUrl != null && bounds.getWidth() > 0 && bounds.getHeight() > 0)

{

Image img = loadImage(imageUrl);

if (img != null)

{

int w, h;

int x = bounds.x;

int y = bounds.y;

Dimension size = getImageSize(img);

if (preserveAspect)

{

double s = Math.min(bounds.width / (double) size.width,

bounds.height / (double) size.height);

w = (int) (size.width * s);

h = (int) (size.height * s);

x += (bounds.width - w) / 2;

y += (bounds.height - h) / 2;

}

else

{

w = bounds.width;

h = bounds.height;

}

Image scaledImage = (w == size.width && h == size.height) ? img

: img.getScaledInstance(w, h, IMAGE_SCALING);

if (scaledImage != null)

{

AffineTransform af = null;

if (flipH || flipV)

{

af = g.getTransform();

int sx = 1;

int sy = 1;

int dx = 0;

int dy = 0;

if (flipH)

{

sx = -1;

dx = -w - 2 * x;

}

if (flipV)

{

sy = -1;

dy = -h - 2 * y;

}

g.scale(sx, sy);

g.translate(dx, dy);

}

drawImageImpl(scaledImage, x, y);

// Restores the previous transform

if (af != null)

{

g.setTransform(af);

}

}

}

}

}

開發者ID:GDSRS,項目名稱:TrabalhoFinalEDA2,代碼行數:75,

示例14: drawImage

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

/**

*

*/

public void drawImage(Rectangle bounds, String imageUrl, boolean preserveAspect, boolean flipH,

boolean flipV) {

if (imageUrl != null && bounds.getWidth() > 0 && bounds.getHeight() > 0) {

Image img = loadImage(imageUrl);

if (img != null) {

int w, h;

int x = bounds.x;

int y = bounds.y;

Dimension size = getImageSize(img);

if (preserveAspect) {

double s =

Math.min(bounds.width / (double) size.width, bounds.height / (double) size.height);

w = (int) (size.width * s);

h = (int) (size.height * s);

x += (bounds.width - w) / 2;

y += (bounds.height - h) / 2;

} else {

w = bounds.width;

h = bounds.height;

}

Image scaledImage = (w == size.width && h == size.height) ? img

: img.getScaledInstance(w, h, IMAGE_SCALING);

if (scaledImage != null) {

AffineTransform af = null;

if (flipH || flipV) {

af = g.getTransform();

int sx = 1;

int sy = 1;

int dx = 0;

int dy = 0;

if (flipH) {

sx = -1;

dx = -w - 2 * x;

}

if (flipV) {

sy = -1;

dy = -h - 2 * y;

}

g.scale(sx, sy);

g.translate(dx, dy);

}

drawImageImpl(scaledImage, x, y);

// Restores the previous transform

if (af != null) {

g.setTransform(af);

}

}

}

}

}

開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:64,

示例15: reescale

​點讚 2

import java.awt.Image; //導入方法依賴的package包/類

private ImageIcon reescale(Image img) {

Image newimg = img.getScaledInstance(16, 16, java.awt.Image.SCALE_SMOOTH);

return new ImageIcon(newimg);

}

開發者ID:chcandido,項目名稱:brModelo,代碼行數:5,

注:本文中的java.awt.Image.getScaledInstance方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值