当前位置: 首页>>代码示例>>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

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,代码来源:ImageUtil.java

示例2: resizeImage

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,代码来源:ImagePanel.java

示例3: loadIcon

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,代码来源:ImageLoader.java

示例4: loadIcon

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,代码来源:ImageLoader.java

示例5: maximizeImage

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,代码来源:MetaDataPanel.java

示例6: insertImage

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,代码来源:CodeUtil.java

示例7: scaleImage

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,代码来源:mxGraphicsCanvas2D.java

示例8: scaleImage

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,代码来源:mxGraphicsCanvas2D.java

示例9: CognizantITSFileChooser

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,代码来源:CognizantITSFileChooser.java

示例10: main

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,代码来源:MultiResolutionCachedImageTest.java

示例11: getScaledImageIcon

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,代码来源:Tools.java

示例12: loadFromResource

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,代码来源:TratadorDeImagens.java

示例13: drawImage

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,代码来源:mxGraphics2DCanvas.java

示例14: drawImage

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,代码来源:mxGraphics2DCanvas.java

示例15: reescale

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,代码来源:Acao.java


注:本文中的java.awt.Image.getScaledInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。